diff --git a/B/00/images/apple.png b/B/00/images/apple.png new file mode 100644 index 0000000..6cc869e Binary files /dev/null and b/B/00/images/apple.png differ diff --git a/B/00/images/ball.png b/B/00/images/ball.png new file mode 100644 index 0000000..4647939 Binary files /dev/null and b/B/00/images/ball.png differ diff --git a/B/00/images/glasses.png b/B/00/images/glasses.png new file mode 100644 index 0000000..ddcccef Binary files /dev/null and b/B/00/images/glasses.png differ diff --git a/B/00/prompt.json b/B/00/prompt.json new file mode 100644 index 0000000..0ceede2 --- /dev/null +++ b/B/00/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Ring", + "1": "Hotel", + "2": "Building", + "3": "Deer", + "4": "Donkey", + "5": "Belt", + "6": "Zebra", + "7": "Milk", + "8": "Onion", + "9": "Temple", + "10": "Pizza", + "11": "Kangaroo", + "12": "Whale", + "13": "Dog", + "14": "Butterfly", + "15": "Cheese", + "16": "Panda", + "17": "Cat", + "18": "Statue", + "19": "Leaf", + "20": "Earrings", + "21": "Sunglasses", + "22": "Boat", + "23": "Swan", + "24": "Pool" +} \ No newline at end of file diff --git a/B/01/images/cactus.png b/B/01/images/cactus.png new file mode 100644 index 0000000..dbacf20 Binary files /dev/null and b/B/01/images/cactus.png differ diff --git a/B/01/images/sunflower.png b/B/01/images/sunflower.png new file mode 100644 index 0000000..136197c Binary files /dev/null and b/B/01/images/sunflower.png differ diff --git a/B/01/images/tree.png b/B/01/images/tree.png new file mode 100644 index 0000000..0c66f9c Binary files /dev/null and b/B/01/images/tree.png differ diff --git a/B/01/prompt.json b/B/01/prompt.json new file mode 100644 index 0000000..b21efed --- /dev/null +++ b/B/01/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Notebook", + "1": "Seed", + "2": "Valley", + "3": "Cheese", + "4": "Ocean", + "5": "Factory", + "6": "Corn", + "7": "Pencil", + "8": "Tulip", + "9": "Lettuce", + "10": "Stadium", + "11": "Boat", + "12": "Fox", + "13": "Snow", + "14": "Train", + "15": "Grass", + "16": "Glasses", + "17": "Computer", + "18": "Cloud", + "19": "Sunglasses", + "20": "Spoon", + "21": "Sunflower", + "22": "Pineapple", + "23": "Juice", + "24": "Park" +} \ No newline at end of file diff --git a/B/02/images/cow.png b/B/02/images/cow.png new file mode 100644 index 0000000..603226d Binary files /dev/null and b/B/02/images/cow.png differ diff --git a/B/02/images/duck.png b/B/02/images/duck.png new file mode 100644 index 0000000..393180d Binary files /dev/null and b/B/02/images/duck.png differ diff --git a/B/02/images/monkey.png b/B/02/images/monkey.png new file mode 100644 index 0000000..93b7d80 Binary files /dev/null and b/B/02/images/monkey.png differ diff --git a/B/02/prompt.json b/B/02/prompt.json new file mode 100644 index 0000000..865815d --- /dev/null +++ b/B/02/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Garage", + "1": "Statue", + "2": "Lion", + "3": "Desk", + "4": "Greenhouse", + "5": "Playground", + "6": "Cucumber", + "7": "Market", + "8": "Zebra", + "9": "Grass", + "10": "Pizza", + "11": "Scarf", + "12": "Hospital", + "13": "Radio", + "14": "Duck", + "15": "Ball", + "16": "Scissors", + "17": "Eagle", + "18": "Shoes", + "19": "Theatre", + "20": "Pineapple", + "21": "Fork", + "22": "Blanket", + "23": "Coffee", + "24": "Clock" +} \ No newline at end of file diff --git a/B/03/images/full_moon.png b/B/03/images/full_moon.png new file mode 100644 index 0000000..4c245f4 Binary files /dev/null and b/B/03/images/full_moon.png differ diff --git a/B/03/images/jumping_fish.png b/B/03/images/jumping_fish.png new file mode 100644 index 0000000..08b6b42 Binary files /dev/null and b/B/03/images/jumping_fish.png differ diff --git a/B/03/images/sitting_rabbit.png b/B/03/images/sitting_rabbit.png new file mode 100644 index 0000000..3aab357 Binary files /dev/null and b/B/03/images/sitting_rabbit.png differ diff --git a/B/03/prompt.json b/B/03/prompt.json new file mode 100644 index 0000000..4485a1a --- /dev/null +++ b/B/03/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Monkey", + "1": "Notebook", + "2": "Cinema", + "3": "Bread", + "4": "Shop", + "5": "Lavender", + "6": "Painting", + "7": "Museum", + "8": "Pencil", + "9": "Factory", + "10": "Cucumber", + "11": "Port", + "12": "Road", + "13": "Barn", + "14": "River", + "15": "Canyon", + "16": "Parrot", + "17": "Glasses", + "18": "Dolphin", + "19": "Suitcase", + "20": "Peach", + "21": "Strawberry", + "22": "Hat", + "23": "Library", + "24": "Key" +} \ No newline at end of file diff --git a/B/04/images/airplane.png b/B/04/images/airplane.png new file mode 100644 index 0000000..170f898 Binary files /dev/null and b/B/04/images/airplane.png differ diff --git a/B/04/images/dove.png b/B/04/images/dove.png new file mode 100644 index 0000000..754a612 Binary files /dev/null and b/B/04/images/dove.png differ diff --git a/B/04/images/snowflake.png b/B/04/images/snowflake.png new file mode 100644 index 0000000..24ed556 Binary files /dev/null and b/B/04/images/snowflake.png differ diff --git a/B/04/prompt.json b/B/04/prompt.json new file mode 100644 index 0000000..91f8242 --- /dev/null +++ b/B/04/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Peacock", + "1": "Volcano", + "2": "Pineapple", + "3": "Computer", + "4": "Chocolate", + "5": "Painting", + "6": "Seed", + "7": "Orange", + "8": "Ship", + "9": "Shelf", + "10": "Tulip", + "11": "Castle", + "12": "Dress", + "13": "Coat", + "14": "Cherry", + "15": "Panda", + "16": "Tomato", + "17": "Bag", + "18": "Duck", + "19": "Workshop", + "20": "Book", + "21": "Apple", + "22": "Gate", + "23": "Greenhouse", + "24": "Lamp" +} \ No newline at end of file diff --git a/B/05/images/map.png b/B/05/images/map.png new file mode 100644 index 0000000..f820e89 Binary files /dev/null and b/B/05/images/map.png differ diff --git a/B/05/images/parrot.png b/B/05/images/parrot.png new file mode 100644 index 0000000..2253d45 Binary files /dev/null and b/B/05/images/parrot.png differ diff --git a/B/05/images/pirate_hat.png b/B/05/images/pirate_hat.png new file mode 100644 index 0000000..96a2909 Binary files /dev/null and b/B/05/images/pirate_hat.png differ diff --git a/B/05/prompt.json b/B/05/prompt.json new file mode 100644 index 0000000..cad09ab --- /dev/null +++ b/B/05/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Zoo", + "1": "Swan", + "2": "Octopus", + "3": "Ocean", + "4": "Cup", + "5": "Rabbit", + "6": "Bag", + "7": "Coffee", + "8": "Hospital", + "9": "Key", + "10": "Tomato", + "11": "Cow", + "12": "Sushi", + "13": "Aquarium", + "14": "Valley", + "15": "Notebook", + "16": "Bear", + "17": "Deer", + "18": "Belt", + "19": "Beach", + "20": "Park", + "21": "Tulip", + "22": "Plate", + "23": "Television", + "24": "Orange" +} \ No newline at end of file diff --git a/B/06/images/mug.png b/B/06/images/mug.png new file mode 100644 index 0000000..248a1a6 Binary files /dev/null and b/B/06/images/mug.png differ diff --git a/B/06/images/orchid.png b/B/06/images/orchid.png new file mode 100644 index 0000000..07ae059 Binary files /dev/null and b/B/06/images/orchid.png differ diff --git a/B/06/images/tulip.png b/B/06/images/tulip.png new file mode 100644 index 0000000..ec9e573 Binary files /dev/null and b/B/06/images/tulip.png differ diff --git a/B/06/prompt.json b/B/06/prompt.json new file mode 100644 index 0000000..11ea9c9 --- /dev/null +++ b/B/06/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Airport", + "1": "Snow", + "2": "Market", + "3": "Painting", + "4": "Hat", + "5": "Cup", + "6": "House", + "7": "Branch", + "8": "Mall", + "9": "River", + "10": "Dog", + "11": "Duck", + "12": "Restaurant", + "13": "Cafe", + "14": "Ice cream", + "15": "Library", + "16": "Onion", + "17": "Coffee", + "18": "Peach", + "19": "Vase", + "20": "Swan", + "21": "Shelf", + "22": "Stadium", + "23": "Fox", + "24": "Barn" +} \ No newline at end of file diff --git a/B/07/images/Cherry_blossom.png b/B/07/images/Cherry_blossom.png new file mode 100644 index 0000000..df20631 Binary files /dev/null and b/B/07/images/Cherry_blossom.png differ diff --git a/B/07/images/city_bus.png b/B/07/images/city_bus.png new file mode 100644 index 0000000..5736737 Binary files /dev/null and b/B/07/images/city_bus.png differ diff --git a/B/07/images/woman_walking_a_dog.png b/B/07/images/woman_walking_a_dog.png new file mode 100644 index 0000000..90564b4 Binary files /dev/null and b/B/07/images/woman_walking_a_dog.png differ diff --git a/B/07/prompt.json b/B/07/prompt.json new file mode 100644 index 0000000..474b7e6 --- /dev/null +++ b/B/07/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Garage", + "1": "Market", + "2": "Bracelet", + "3": "Skateboard", + "4": "Swan", + "5": "Giraffe", + "6": "Beach", + "7": "Desert", + "8": "Road", + "9": "Eagle", + "10": "Mango", + "11": "Pool", + "12": "Towel", + "13": "Camera", + "14": "Sun", + "15": "Brush", + "16": "Hospital", + "17": "Orange", + "18": "Owl", + "19": "Branch", + "20": "Banana", + "21": "Cow", + "22": "Sushi", + "23": "Bamboo", + "24": "Curtain" +} \ No newline at end of file diff --git a/B/08/images/dog.png b/B/08/images/dog.png new file mode 100644 index 0000000..532389e Binary files /dev/null and b/B/08/images/dog.png differ diff --git a/B/08/images/fish.png b/B/08/images/fish.png new file mode 100644 index 0000000..1ff5953 Binary files /dev/null and b/B/08/images/fish.png differ diff --git a/B/08/images/television.png b/B/08/images/television.png new file mode 100644 index 0000000..76e1afb Binary files /dev/null and b/B/08/images/television.png differ diff --git a/B/08/prompt.json b/B/08/prompt.json new file mode 100644 index 0000000..78a0b9c --- /dev/null +++ b/B/08/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Pool", + "1": "Computer", + "2": "Windmill", + "3": "Cow", + "4": "Key", + "5": "Swan", + "6": "Bus", + "7": "Sand", + "8": "Desk", + "9": "Pencil", + "10": "Cheese", + "11": "Chocolate", + "12": "Tiger", + "13": "Tulip", + "14": "Water", + "15": "Lavender", + "16": "Banana", + "17": "Medicine", + "18": "Temple", + "19": "Bridge", + "20": "Milk", + "21": "Plate", + "22": "Bottle", + "23": "Dolphin", + "24": "Cloud" +} \ No newline at end of file diff --git a/B/09/images/Trees.png b/B/09/images/Trees.png new file mode 100644 index 0000000..8f45de8 Binary files /dev/null and b/B/09/images/Trees.png differ diff --git a/B/09/images/bicycle.png b/B/09/images/bicycle.png new file mode 100644 index 0000000..cd4bf4a Binary files /dev/null and b/B/09/images/bicycle.png differ diff --git a/B/09/images/bird.png b/B/09/images/bird.png new file mode 100644 index 0000000..460760a Binary files /dev/null and b/B/09/images/bird.png differ diff --git a/B/09/prompt.json b/B/09/prompt.json new file mode 100644 index 0000000..51ea78e --- /dev/null +++ b/B/09/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Tower", + "1": "Museum", + "2": "River", + "3": "Water", + "4": "Station", + "5": "Television", + "6": "Mango", + "7": "Coat", + "8": "Cherry", + "9": "Glasses", + "10": "Ball", + "11": "Road", + "12": "Cloud", + "13": "Computer", + "14": "Carrot", + "15": "Onion", + "16": "Phone", + "17": "Island", + "18": "Earrings", + "19": "Panda", + "20": "Lettuce", + "21": "Rabbit", + "22": "Greenhouse", + "23": "House", + "24": "Key" +} \ No newline at end of file diff --git a/B/10/images/chess_set.png b/B/10/images/chess_set.png new file mode 100644 index 0000000..bc6e797 Binary files /dev/null and b/B/10/images/chess_set.png differ diff --git a/B/10/images/record_player.png b/B/10/images/record_player.png new file mode 100644 index 0000000..a3ccf49 Binary files /dev/null and b/B/10/images/record_player.png differ diff --git a/B/10/images/retro_radio.png b/B/10/images/retro_radio.png new file mode 100644 index 0000000..8e917ee Binary files /dev/null and b/B/10/images/retro_radio.png differ diff --git a/B/10/prompt.json b/B/10/prompt.json new file mode 100644 index 0000000..18da5eb --- /dev/null +++ b/B/10/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Station", + "1": "Building", + "2": "Grapes", + "3": "Bee", + "4": "Desert", + "5": "Monkey", + "6": "Fox", + "7": "Pants", + "8": "Chocolate", + "9": "Watch", + "10": "Rabbit", + "11": "Medicine", + "12": "Skateboard", + "13": "Eagle", + "14": "Rug", + "15": "Glasses", + "16": "Moon", + "17": "Umbrella", + "18": "Mirror", + "19": "Pool", + "20": "Shop", + "21": "Burger", + "22": "Necklace", + "23": "Panda", + "24": "Sunflower" +} \ No newline at end of file diff --git a/B/11/images/fish.png b/B/11/images/fish.png new file mode 100644 index 0000000..0e5dbf0 Binary files /dev/null and b/B/11/images/fish.png differ diff --git a/B/11/images/house.png b/B/11/images/house.png new file mode 100644 index 0000000..c5c9c29 Binary files /dev/null and b/B/11/images/house.png differ diff --git a/B/11/images/moon.png b/B/11/images/moon.png new file mode 100644 index 0000000..9cfc3c9 Binary files /dev/null and b/B/11/images/moon.png differ diff --git a/B/11/prompt.json b/B/11/prompt.json new file mode 100644 index 0000000..165a6b8 --- /dev/null +++ b/B/11/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Glove", + "1": "Burger", + "2": "Hat", + "3": "Star", + "4": "Bottle", + "5": "Port", + "6": "Sushi", + "7": "Swan", + "8": "Kangaroo", + "9": "Canyon", + "10": "Smoke", + "11": "Fork", + "12": "Cheese", + "13": "Station", + "14": "Cat", + "15": "Mall", + "16": "Pool", + "17": "Pizza", + "18": "Sunglasses", + "19": "Gallery", + "20": "Cup", + "21": "Fence", + "22": "Lighthouse", + "23": "Car", + "24": "Hotel" +} \ No newline at end of file diff --git a/B/12/images/apple.png b/B/12/images/apple.png new file mode 100644 index 0000000..af5e62d Binary files /dev/null and b/B/12/images/apple.png differ diff --git a/B/12/images/bed.png b/B/12/images/bed.png new file mode 100644 index 0000000..359775d Binary files /dev/null and b/B/12/images/bed.png differ diff --git a/B/12/images/bottle.png b/B/12/images/bottle.png new file mode 100644 index 0000000..48643d6 Binary files /dev/null and b/B/12/images/bottle.png differ diff --git a/B/12/prompt.json b/B/12/prompt.json new file mode 100644 index 0000000..a0d452f --- /dev/null +++ b/B/12/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Statue", + "1": "Rock", + "2": "Potato", + "3": "Pencil", + "4": "Aquarium", + "5": "Owl", + "6": "Lettuce", + "7": "Farm", + "8": "Falcon", + "9": "Pillow", + "10": "Wallet", + "11": "Tomato", + "12": "Milk", + "13": "Soda", + "14": "Studio", + "15": "Grass", + "16": "Sushi", + "17": "Bear", + "18": "Belt", + "19": "Brush", + "20": "Desk", + "21": "Camera", + "22": "Rocket", + "23": "Lobster", + "24": "Watermelon" +} \ No newline at end of file diff --git a/B/13/images/bamboo.png b/B/13/images/bamboo.png new file mode 100644 index 0000000..3a674ff Binary files /dev/null and b/B/13/images/bamboo.png differ diff --git a/B/13/images/cat.png b/B/13/images/cat.png new file mode 100644 index 0000000..71d7b32 Binary files /dev/null and b/B/13/images/cat.png differ diff --git a/B/13/images/house.png b/B/13/images/house.png new file mode 100644 index 0000000..86bf0e6 Binary files /dev/null and b/B/13/images/house.png differ diff --git a/B/13/prompt.json b/B/13/prompt.json new file mode 100644 index 0000000..4f31c8f --- /dev/null +++ b/B/13/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Cow", + "1": "Bed", + "2": "Dress", + "3": "Strawberry", + "4": "Octopus", + "5": "Juice", + "6": "Pool", + "7": "Rose", + "8": "Ship", + "9": "Desk", + "10": "Star", + "11": "Park", + "12": "Zoo", + "13": "Seed", + "14": "Banana", + "15": "Elephant", + "16": "Umbrella", + "17": "Shoes", + "18": "Plate", + "19": "Waterfall", + "20": "Chocolate", + "21": "Chair", + "22": "Knife", + "23": "Fire", + "24": "Canyon" +} \ No newline at end of file diff --git a/B/14/images/galloping_horse.png b/B/14/images/galloping_horse.png new file mode 100644 index 0000000..2595be7 Binary files /dev/null and b/B/14/images/galloping_horse.png differ diff --git a/B/14/images/ram_headbutting.png b/B/14/images/ram_headbutting.png new file mode 100644 index 0000000..81b6bc6 Binary files /dev/null and b/B/14/images/ram_headbutting.png differ diff --git a/B/14/images/soaring_eagle.png b/B/14/images/soaring_eagle.png new file mode 100644 index 0000000..4379e87 Binary files /dev/null and b/B/14/images/soaring_eagle.png differ diff --git a/B/14/prompt.json b/B/14/prompt.json new file mode 100644 index 0000000..ea8f137 --- /dev/null +++ b/B/14/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Knife", + "1": "Cup", + "2": "Waterfall", + "3": "Park", + "4": "Hat", + "5": "Kangaroo", + "6": "Backpack", + "7": "Bee", + "8": "Sushi", + "9": "Hotel", + "10": "Chocolate", + "11": "Lobster", + "12": "Painting", + "13": "Island", + "14": "Blanket", + "15": "Grass", + "16": "Zebra", + "17": "Water", + "18": "Desk", + "19": "Fork", + "20": "Soda", + "21": "Sun", + "22": "Plate", + "23": "Watch", + "24": "Rug" +} \ No newline at end of file diff --git a/B/15/images/astronaut.png b/B/15/images/astronaut.png new file mode 100644 index 0000000..4cc9195 Binary files /dev/null and b/B/15/images/astronaut.png differ diff --git a/B/15/images/golfer.png b/B/15/images/golfer.png new file mode 100644 index 0000000..5b7f835 Binary files /dev/null and b/B/15/images/golfer.png differ diff --git a/B/15/images/snowboarder.png b/B/15/images/snowboarder.png new file mode 100644 index 0000000..a734a62 Binary files /dev/null and b/B/15/images/snowboarder.png differ diff --git a/B/15/prompt.json b/B/15/prompt.json new file mode 100644 index 0000000..e48ee58 --- /dev/null +++ b/B/15/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Notebook", + "1": "Forest", + "2": "Mirror", + "3": "Mall", + "4": "Mango", + "5": "Strawberry", + "6": "Grapes", + "7": "Corn", + "8": "Wallet", + "9": "Bicycle", + "10": "Watch", + "11": "Zebra", + "12": "Bed", + "13": "Duck", + "14": "Library", + "15": "Dress", + "16": "Owl", + "17": "Fish", + "18": "Kangaroo", + "19": "Radio", + "20": "Rock", + "21": "Table", + "22": "River", + "23": "Cucumber", + "24": "Medicine" +} \ No newline at end of file diff --git a/B/16/images/bird.png b/B/16/images/bird.png new file mode 100644 index 0000000..a9c04a1 Binary files /dev/null and b/B/16/images/bird.png differ diff --git a/B/16/images/bottle.png b/B/16/images/bottle.png new file mode 100644 index 0000000..0b41898 Binary files /dev/null and b/B/16/images/bottle.png differ diff --git a/B/16/images/dog.png b/B/16/images/dog.png new file mode 100644 index 0000000..fb77d11 Binary files /dev/null and b/B/16/images/dog.png differ diff --git a/B/16/prompt.json b/B/16/prompt.json new file mode 100644 index 0000000..f9497e1 --- /dev/null +++ b/B/16/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Tiger", + "1": "Lake", + "2": "Ant", + "3": "Leaf", + "4": "Stadium", + "5": "Apple", + "6": "Cinema", + "7": "Boat", + "8": "Falcon", + "9": "Canyon", + "10": "Bracelet", + "11": "Flower", + "12": "Skateboard", + "13": "Gate", + "14": "Hospital", + "15": "Towel", + "16": "Suitcase", + "17": "Shed", + "18": "Rock", + "19": "Pants", + "20": "Kangaroo", + "21": "Computer", + "22": "Sofa", + "23": "Wolf", + "24": "Bed" +} \ No newline at end of file diff --git a/B/17/images/Glacier.png b/B/17/images/Glacier.png new file mode 100644 index 0000000..bb6eecc Binary files /dev/null and b/B/17/images/Glacier.png differ diff --git a/B/17/images/flowing_river.png b/B/17/images/flowing_river.png new file mode 100644 index 0000000..196de50 Binary files /dev/null and b/B/17/images/flowing_river.png differ diff --git a/B/17/images/majestic_waterfall.png b/B/17/images/majestic_waterfall.png new file mode 100644 index 0000000..a0a7b05 Binary files /dev/null and b/B/17/images/majestic_waterfall.png differ diff --git a/B/17/prompt.json b/B/17/prompt.json new file mode 100644 index 0000000..daf0284 --- /dev/null +++ b/B/17/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Falcon", + "1": "Ring", + "2": "Pool", + "3": "Soda", + "4": "Mountain", + "5": "Canyon", + "6": "Star", + "7": "Key", + "8": "Aquarium", + "9": "Bottle", + "10": "Panda", + "11": "Port", + "12": "Sushi", + "13": "Glasses", + "14": "Elephant", + "15": "Rug", + "16": "Tiger", + "17": "Coffee", + "18": "Volcano", + "19": "Bed", + "20": "Factory", + "21": "Coat", + "22": "Barn", + "23": "Valley", + "24": "Milk" +} \ No newline at end of file diff --git a/B/18/images/cow.png b/B/18/images/cow.png new file mode 100644 index 0000000..1f30fd0 Binary files /dev/null and b/B/18/images/cow.png differ diff --git a/B/18/images/frog.png b/B/18/images/frog.png new file mode 100644 index 0000000..bf6f6c0 Binary files /dev/null and b/B/18/images/frog.png differ diff --git a/B/18/images/squirrel.png b/B/18/images/squirrel.png new file mode 100644 index 0000000..049cb47 Binary files /dev/null and b/B/18/images/squirrel.png differ diff --git a/B/18/prompt.json b/B/18/prompt.json new file mode 100644 index 0000000..f778648 --- /dev/null +++ b/B/18/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Lake", + "1": "Tower", + "2": "Owl", + "3": "Mango", + "4": "Necklace", + "5": "Tea", + "6": "Fox", + "7": "Garage", + "8": "Earrings", + "9": "Brush", + "10": "Plate", + "11": "Computer", + "12": "Panda", + "13": "Fence", + "14": "Pillow", + "15": "Scooter", + "16": "Water", + "17": "Road", + "18": "Office", + "19": "Butterfly", + "20": "Park", + "21": "Bee", + "22": "House", + "23": "Waterfall", + "24": "Windmill" +} \ No newline at end of file diff --git a/B/19/images/Lion.png b/B/19/images/Lion.png new file mode 100644 index 0000000..90af3c1 Binary files /dev/null and b/B/19/images/Lion.png differ diff --git a/B/19/images/Zebra.png b/B/19/images/Zebra.png new file mode 100644 index 0000000..4459b0b Binary files /dev/null and b/B/19/images/Zebra.png differ diff --git a/B/19/images/dog.png b/B/19/images/dog.png new file mode 100644 index 0000000..0643f3c Binary files /dev/null and b/B/19/images/dog.png differ diff --git a/B/19/prompt.json b/B/19/prompt.json new file mode 100644 index 0000000..fd91fc0 --- /dev/null +++ b/B/19/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Cherry", + "1": "Island", + "2": "Peacock", + "3": "Scarf", + "4": "Lettuce", + "5": "Tree", + "6": "Fork", + "7": "Fish", + "8": "Towel", + "9": "Statue", + "10": "Bracelet", + "11": "Table", + "12": "Banana", + "13": "Sand", + "14": "Lighthouse", + "15": "Ship", + "16": "Gallery", + "17": "Umbrella", + "18": "Swan", + "19": "Dog", + "20": "Windmill", + "21": "Spoon", + "22": "Fire", + "23": "Tomato", + "24": "Cup" +} \ No newline at end of file diff --git a/B/20/images/dragon.png b/B/20/images/dragon.png new file mode 100644 index 0000000..fe09661 Binary files /dev/null and b/B/20/images/dragon.png differ diff --git a/B/20/images/phoenix.png b/B/20/images/phoenix.png new file mode 100644 index 0000000..511d426 Binary files /dev/null and b/B/20/images/phoenix.png differ diff --git a/B/20/images/wizard.png b/B/20/images/wizard.png new file mode 100644 index 0000000..3f00b7b Binary files /dev/null and b/B/20/images/wizard.png differ diff --git a/B/20/prompt.json b/B/20/prompt.json new file mode 100644 index 0000000..edf6507 --- /dev/null +++ b/B/20/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Plane", + "1": "Opera", + "2": "Bottle", + "3": "Beach", + "4": "Pants", + "5": "Ship", + "6": "Grass", + "7": "Rose", + "8": "Shoes", + "9": "Computer", + "10": "Ring", + "11": "Watch", + "12": "Rocket", + "13": "Cat", + "14": "Volcano", + "15": "Tiger", + "16": "Scissors", + "17": "Zoo", + "18": "Soda", + "19": "Fox", + "20": "Plate", + "21": "Lavender", + "22": "Book", + "23": "Dog", + "24": "Bracelet" +} \ No newline at end of file diff --git a/B/21/images/Backpack.png b/B/21/images/Backpack.png new file mode 100644 index 0000000..79700e6 Binary files /dev/null and b/B/21/images/Backpack.png differ diff --git a/B/21/images/Dolphin.png b/B/21/images/Dolphin.png new file mode 100644 index 0000000..374a4ef Binary files /dev/null and b/B/21/images/Dolphin.png differ diff --git a/B/21/images/Lion.png b/B/21/images/Lion.png new file mode 100644 index 0000000..95e92cd Binary files /dev/null and b/B/21/images/Lion.png differ diff --git a/B/21/prompt.json b/B/21/prompt.json new file mode 100644 index 0000000..9035750 --- /dev/null +++ b/B/21/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Zebra", + "1": "Flower", + "2": "Plane", + "3": "Hotel", + "4": "Tea", + "5": "Airport", + "6": "Mirror", + "7": "Curtain", + "8": "Lobster", + "9": "Cafe", + "10": "Bus", + "11": "Pencil", + "12": "Forest", + "13": "Office", + "14": "Knife", + "15": "Blanket", + "16": "Carrot", + "17": "Duck", + "18": "Elephant", + "19": "Pants", + "20": "Sheep", + "21": "Tree", + "22": "Laptop", + "23": "Restaurant", + "24": "Burger" +} \ No newline at end of file diff --git a/B/22/images/blender.png b/B/22/images/blender.png new file mode 100644 index 0000000..1b63fc9 Binary files /dev/null and b/B/22/images/blender.png differ diff --git a/B/22/images/drum_set.png b/B/22/images/drum_set.png new file mode 100644 index 0000000..0cba7aa Binary files /dev/null and b/B/22/images/drum_set.png differ diff --git a/B/22/images/vase.png b/B/22/images/vase.png new file mode 100644 index 0000000..a6e2dd2 Binary files /dev/null and b/B/22/images/vase.png differ diff --git a/B/22/prompt.json b/B/22/prompt.json new file mode 100644 index 0000000..28e53dd --- /dev/null +++ b/B/22/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "House", + "1": "Boat", + "2": "Dog", + "3": "Notebook", + "4": "Eagle", + "5": "Market", + "6": "Bag", + "7": "Port", + "8": "Coffee", + "9": "Headphones", + "10": "Pillow", + "11": "Lobster", + "12": "Waterfall", + "13": "Leaf", + "14": "Mirror", + "15": "Key", + "16": "Sofa", + "17": "Umbrella", + "18": "Train", + "19": "Camera", + "20": "Panda", + "21": "Beach", + "22": "Plane", + "23": "Donkey", + "24": "Fire" +} \ No newline at end of file diff --git a/B/23/images/cupcake.png b/B/23/images/cupcake.png new file mode 100644 index 0000000..d7f81df Binary files /dev/null and b/B/23/images/cupcake.png differ diff --git a/B/23/images/pair_of_sneakers.png b/B/23/images/pair_of_sneakers.png new file mode 100644 index 0000000..206d4c1 Binary files /dev/null and b/B/23/images/pair_of_sneakers.png differ diff --git a/B/23/images/robot.png b/B/23/images/robot.png new file mode 100644 index 0000000..574d02d Binary files /dev/null and b/B/23/images/robot.png differ diff --git a/B/23/prompt.json b/B/23/prompt.json new file mode 100644 index 0000000..b1890c0 --- /dev/null +++ b/B/23/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Water", + "1": "Sunflower", + "2": "Chair", + "3": "Seed", + "4": "Leaf", + "5": "School", + "6": "Smoke", + "7": "Desert", + "8": "Juice", + "9": "Apple", + "10": "Spoon", + "11": "Fence", + "12": "Watch", + "13": "Chocolate", + "14": "Ant", + "15": "Potato", + "16": "Grass", + "17": "Monkey", + "18": "Airport", + "19": "Elephant", + "20": "Theatre", + "21": "Necklace", + "22": "Aquarium", + "23": "Island", + "24": "Dress" +} \ No newline at end of file diff --git a/B/24/images/cactus_made.png b/B/24/images/cactus_made.png new file mode 100644 index 0000000..20c2765 Binary files /dev/null and b/B/24/images/cactus_made.png differ diff --git a/B/24/images/chair_made.png b/B/24/images/chair_made.png new file mode 100644 index 0000000..e84830c Binary files /dev/null and b/B/24/images/chair_made.png differ diff --git a/B/24/images/pine_tree_made.png b/B/24/images/pine_tree_made.png new file mode 100644 index 0000000..ff2f39d Binary files /dev/null and b/B/24/images/pine_tree_made.png differ diff --git a/B/24/prompt.json b/B/24/prompt.json new file mode 100644 index 0000000..ac3578b --- /dev/null +++ b/B/24/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Boat", + "1": "Bee", + "2": "Rug", + "3": "Shop", + "4": "Workshop", + "5": "Chair", + "6": "Fox", + "7": "Medicine", + "8": "Flower", + "9": "Coffee", + "10": "Bear", + "11": "Branch", + "12": "Plate", + "13": "Brush", + "14": "Swan", + "15": "Clock", + "16": "Tree", + "17": "Lake", + "18": "Shark", + "19": "Painting", + "20": "Lighthouse", + "21": "Knife", + "22": "Owl", + "23": "Dog", + "24": "Spoon" +} \ No newline at end of file diff --git a/B/25/images/bitmapped_flower.png b/B/25/images/bitmapped_flower.png new file mode 100644 index 0000000..9e0d0d8 Binary files /dev/null and b/B/25/images/bitmapped_flower.png differ diff --git a/B/25/images/pixel_art_cat.png b/B/25/images/pixel_art_cat.png new file mode 100644 index 0000000..952e29b Binary files /dev/null and b/B/25/images/pixel_art_cat.png differ diff --git a/B/25/images/pixel_art_sword.png b/B/25/images/pixel_art_sword.png new file mode 100644 index 0000000..41374df Binary files /dev/null and b/B/25/images/pixel_art_sword.png differ diff --git a/B/25/prompt.json b/B/25/prompt.json new file mode 100644 index 0000000..3e5ec0f --- /dev/null +++ b/B/25/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Statue", + "1": "Shark", + "2": "Ball", + "3": "Eagle", + "4": "Museum", + "5": "Knife", + "6": "Octopus", + "7": "Donkey", + "8": "Grass", + "9": "Scooter", + "10": "Sunglasses", + "11": "Stadium", + "12": "Butterfly", + "13": "Phone", + "14": "Owl", + "15": "Airport", + "16": "Factory", + "17": "Rug", + "18": "Hospital", + "19": "Aquarium", + "20": "Zoo", + "21": "Port", + "22": "Cinema", + "23": "Mountain", + "24": "Pencil" +} \ No newline at end of file diff --git a/B/26/images/chicken.png b/B/26/images/chicken.png new file mode 100644 index 0000000..6a23489 Binary files /dev/null and b/B/26/images/chicken.png differ diff --git a/B/26/images/pig.png b/B/26/images/pig.png new file mode 100644 index 0000000..55c57af Binary files /dev/null and b/B/26/images/pig.png differ diff --git a/B/26/images/sunflower_field.png b/B/26/images/sunflower_field.png new file mode 100644 index 0000000..57158c9 Binary files /dev/null and b/B/26/images/sunflower_field.png differ diff --git a/B/26/prompt.json b/B/26/prompt.json new file mode 100644 index 0000000..e1582e8 --- /dev/null +++ b/B/26/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Painting", + "1": "Backpack", + "2": "Scarf", + "3": "Bag", + "4": "Bracelet", + "5": "Table", + "6": "Ant", + "7": "Hotel", + "8": "Lettuce", + "9": "Valley", + "10": "Beach", + "11": "Leaf", + "12": "Port", + "13": "Fork", + "14": "Pool", + "15": "Cafe", + "16": "Branch", + "17": "Market", + "18": "Milk", + "19": "Library", + "20": "Cherry", + "21": "Brush", + "22": "Glasses", + "23": "Moon", + "24": "Laptop" +} \ No newline at end of file diff --git a/B/27/images/bottle.png b/B/27/images/bottle.png new file mode 100644 index 0000000..22e7ac0 Binary files /dev/null and b/B/27/images/bottle.png differ diff --git a/B/27/images/car.png b/B/27/images/car.png new file mode 100644 index 0000000..f42c734 Binary files /dev/null and b/B/27/images/car.png differ diff --git a/B/27/images/shoe.png b/B/27/images/shoe.png new file mode 100644 index 0000000..96d71e1 Binary files /dev/null and b/B/27/images/shoe.png differ diff --git a/B/27/prompt.json b/B/27/prompt.json new file mode 100644 index 0000000..209c81b --- /dev/null +++ b/B/27/prompt.json @@ -0,0 +1,27 @@ +{ + "0": "Swan", + "1": "Bag", + "2": "Watch", + "3": "Sushi", + "4": "Peacock", + "5": "Television", + "6": "Burger", + "7": "Wallet", + "8": "Table", + "9": "School", + "10": "Whale", + "11": "Cabinet", + "12": "Temple", + "13": "Dolphin", + "14": "Lettuce", + "15": "Camera", + "16": "Desk", + "17": "Sheep", + "18": "Peach", + "19": "Waterfall", + "20": "Ice cream", + "21": "Towel", + "22": "Train", + "23": "Rocket", + "24": "Forest" +} \ No newline at end of file diff --git a/LICENSE b/LICENSE index de14edb..ed917bf 100644 --- a/LICENSE +++ b/LICENSE @@ -2,8 +2,20 @@ MIT License Copyright (c) 2024 yohu-cqu -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 21bdd82..3ed5c87 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ -# jittor-SimpleTest-StableDiffusion-B +# DreamBooth-Lora +本项目参考自 [JDiffusion 的 DreamBooth-Lora](https://github.com/JittorRepos/JDiffusion/tree/master/examples/dreambooth) 。 + +## 环境安装 + +按照 [JDiffusion 的环境安装一节](https://github.com/JittorRepos/JDiffusion/blob/master/examples/dreambooth/README.md) 安装必要的依赖。 + +接着设置运行脚本的权限: +``` +chmod u+x ./dreambooth/*.sh +``` + +## 训练 + +1. 首先从比赛云盘下载对应的数据集,推荐将数据集目录 `B` 下载到 `./B` 下 +2. 将 `train_all.sh` 中的 `HF_HOME` 设置为本地模型路径, `root` 设置为项目所在目录, `BASE_INSTANCE_DIR` 设置为数据集对应的目录,`GPU_COUNT` 设置为对应可用的显卡数量,`MAX_NUM` 设置为数据集中的风格个数; +3. 然后进入目标文件夹下: `cd ./dreambooth/`, 运行 `bash train_all.sh` 即可训练。保存的模型会存放至 `./dreambooth/results/prompt_v1_cosine_test/style_[训练epoch数]epoch` 目录下,例如:`./dreambooth/results/prompt_v1_cosine_test/style_300epoch`。 + +## 推理 + +1. 将 `test_all.sh` 中的 `HF_HOME` 设置为本地模型路径,将 `run_all.py` 中的 `root` 设置为项目所在目录, `dataset_root` 修改为数据集对应的目录,将 `max_num` 修改为数据集中的风格个数; +2. 进入目标文件夹下: `cd ./dreambooth/`,运行 `bash test_all.sh` 进行推理。模型生成的图片会输出到 `./dreambooth/results/prompt_v1_cosine_test/outputs_[保存点训练epoch数]ckpt_[推理轮数]steps_[种子值]seed` 文件夹下,例如:`./dreambooth/results/prompt_v1_cosine_test/outputs_300ckpt_200steps_76587seed`。 + + +## 参考文献 + +``` +@inproceedings{ruiz2023dreambooth, + title={Dreambooth: Fine tuning text-to-image diffusion models for subject-driven generation}, + author={Ruiz, Nataniel and Li, Yuanzhen and Jampani, Varun and Pritch, Yael and Rubinstein, Michael and Aberman, Kfir}, + booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition}, + year={2023} +} +``` diff --git a/dreambooth/read_json.py b/dreambooth/read_json.py new file mode 100644 index 0000000..c3f1e6c --- /dev/null +++ b/dreambooth/read_json.py @@ -0,0 +1,19 @@ +import json +import sys + +def get_value_from_json(file_path, key): + with open(file_path, 'r') as f: + data = json.load(f) + if key in data: + return data[key] + else: + return None + +if __name__ == "__main__": + file_path = sys.argv[1] + key = sys.argv[2] + value = get_value_from_json(file_path, key) + if value is not None: + print(value) + else: + sys.exit(1) diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_00/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_00/pytorch_lora_weights.bin new file mode 100644 index 0000000..8e6a811 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_00/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_01/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_01/pytorch_lora_weights.bin new file mode 100644 index 0000000..1d44b5b Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_01/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_02/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_02/pytorch_lora_weights.bin new file mode 100644 index 0000000..e1e5a19 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_02/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_03/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_03/pytorch_lora_weights.bin new file mode 100644 index 0000000..a5a50a8 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_03/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_04/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_04/pytorch_lora_weights.bin new file mode 100644 index 0000000..774015f Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_04/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_05/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_05/pytorch_lora_weights.bin new file mode 100644 index 0000000..148e126 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_05/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_06/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_06/pytorch_lora_weights.bin new file mode 100644 index 0000000..4c88144 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_06/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_07/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_07/pytorch_lora_weights.bin new file mode 100644 index 0000000..c1c5893 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_07/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_08/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_08/pytorch_lora_weights.bin new file mode 100644 index 0000000..c90da9f Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_08/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_09/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_09/pytorch_lora_weights.bin new file mode 100644 index 0000000..22c05fd Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_09/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_10/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_10/pytorch_lora_weights.bin new file mode 100644 index 0000000..7edc491 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_10/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_11/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_11/pytorch_lora_weights.bin new file mode 100644 index 0000000..fe4b3b5 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_11/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_12/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_12/pytorch_lora_weights.bin new file mode 100644 index 0000000..b884753 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_12/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_13/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_13/pytorch_lora_weights.bin new file mode 100644 index 0000000..5a1af40 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_13/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_14/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_14/pytorch_lora_weights.bin new file mode 100644 index 0000000..1889fe6 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_14/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_15/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_15/pytorch_lora_weights.bin new file mode 100644 index 0000000..638fe35 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_15/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_16/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_16/pytorch_lora_weights.bin new file mode 100644 index 0000000..c381ac3 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_16/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_17/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_17/pytorch_lora_weights.bin new file mode 100644 index 0000000..c0cf540 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_17/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_18/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_18/pytorch_lora_weights.bin new file mode 100644 index 0000000..48f2db7 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_18/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_19/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_19/pytorch_lora_weights.bin new file mode 100644 index 0000000..c851d8c Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_19/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_20/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_20/pytorch_lora_weights.bin new file mode 100644 index 0000000..a47c835 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_20/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_21/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_21/pytorch_lora_weights.bin new file mode 100644 index 0000000..1689d60 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_21/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_22/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_22/pytorch_lora_weights.bin new file mode 100644 index 0000000..e5dc09d Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_22/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_23/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_23/pytorch_lora_weights.bin new file mode 100644 index 0000000..ace631a Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_23/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_24/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_24/pytorch_lora_weights.bin new file mode 100644 index 0000000..30f24cb Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_24/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_25/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_25/pytorch_lora_weights.bin new file mode 100644 index 0000000..961fde5 Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_25/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_26/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_26/pytorch_lora_weights.bin new file mode 100644 index 0000000..735ca9f Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_26/pytorch_lora_weights.bin differ diff --git a/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_27/pytorch_lora_weights.bin b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_27/pytorch_lora_weights.bin new file mode 100644 index 0000000..2ca293c Binary files /dev/null and b/dreambooth/results/prompt_v1_cosine_test/style_300epoch/style_27/pytorch_lora_weights.bin differ diff --git a/dreambooth/run_all.py b/dreambooth/run_all.py new file mode 100644 index 0000000..32907de --- /dev/null +++ b/dreambooth/run_all.py @@ -0,0 +1,53 @@ +import os, sys + +os.environ["HF_ENDPOINT"] = "https://hf-mirror.com" +# os.environ["HF_HOME"] = "/home/user1/jittor2024/JDiffusion/cached_path" + +import json, tqdm, torch +import jittor as jt +jt.flags.use_rocm = 1 + +from JDiffusion.pipelines import StableDiffusionPipeline + +root="/home/user1/jittor2024/jittor-B-commit" +save_root = f"{root}/dreambooth/results/" + "prompt_v1_cosine_test" + +max_num = 28 +inference_steps = 200 +checkpoint_epoch = 300 +seed = 76587 +jt.set_global_seed(seed) +dataset_root = f"{root}/B/" +style_file = f"{root}/dreambooth/settings/style.json" +texture_file = f"{root}/dreambooth/settings/texture.json" +color_file = f"{root}/dreambooth/settings/color.json" + +with open(style_file, "r") as f: + style_dict = json.load(f) + +with open(texture_file, "r") as f: + texture_dict = json.load(f) + +with open(color_file, "r") as f: + color_dict = json.load(f) + +pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1").to("cuda") +with torch.no_grad(): + for tempid in tqdm.tqdm(range(0, max_num)): + taskid = "{:0>2d}".format(tempid) + if checkpoint_epoch is None: + pipe.load_lora_weights(os.path.join(save_root, f"style/style_{taskid}")) + else: + pipe.load_lora_weights(os.path.join(save_root, f"style_{checkpoint_epoch}epoch/style_{taskid}")) + + # load json + with open(f"{dataset_root}/{taskid}/prompt.json", "r") as file: + prompts = json.load(file) + + for id, prompt in prompts.items(): + new_prompt = f"A photo of {prompt} in {style_dict[taskid]} style, with a texture of {texture_dict[taskid]} and with a color style of {color_dict[taskid]}." + print(new_prompt) + image = pipe(prompt=new_prompt, num_inference_steps=inference_steps, width=512, height=512, seed=seed).images[0] + print(os.path.join(save_root, f"outputs_{checkpoint_epoch}ckpt_{inference_steps}steps_{seed}seed/{taskid}")) + os.makedirs(os.path.join(save_root, f"outputs_{checkpoint_epoch}ckpt_{inference_steps}steps_{seed}seed/{taskid}"), exist_ok=True) + image.save(os.path.join(save_root, f"outputs_{checkpoint_epoch}ckpt_{inference_steps}steps_{seed}seed/{taskid}/{prompt}.png")) diff --git a/dreambooth/settings/color.json b/dreambooth/settings/color.json new file mode 100644 index 0000000..e9f9925 --- /dev/null +++ b/dreambooth/settings/color.json @@ -0,0 +1,30 @@ +{ + "00": "pink, purple, and yellow hues", + "01": "warm tones, autumnal hues, and vivid contrasts", + "02": "earthy tones, vibrant accents, and monochromatic highlights", + "03": "grayscale", + "04": "light blue sky, bright white clouds, and vivid contrasts", + "05": "rich earth tones, vibrant accents, and monochromatic elements", + "06": "monochromatic red on a pale background", + "07": "featuring warm hues such as pastel pinks, muted oranges, and earthy tones", + "08": "monochromatic beige and cream tones", + "09": "muted pastels, warm earth tones, and subtle gradients", + "10": "warm sepia tones, muted earthy hues, and rich burnt oranges", + "11": "vivid contrasts, warm tones, and harmonious saturation", + "12": "bright, saturated, vibrant and contrasting colors", + "13": "palette dominated by shades of black, white, and subtle hints of red", + "14": "monochromatic", + "15": "electric pink, glowing green, and radiant yellow", + "16": "vibrant, naturalistic, and harmonious blending", + "17": "palette of muted earth tones, cool blues, and warm sunset hues", + "18": "Warm Tones, Natural Palette, and Subdued Brightness", + "19": "vivid contrasts, primary colors, and monochromatic patterns", + "20": "monochromatic sepia tones, muted earthy hues, and grayscale variations", + "21": "Natural, Earthy, and Monochromatic", + "22": "warm earth tones, muted browns and oranges, and subtle gradient transitions", + "23": "minimalistic, muted, and neutral tones", + "24": "bright green, fiery orange-red, and rich red-green gradients", + "25": "earth tones, muted shades, and subtle gradients", + "26": "vivid and contrasting hues", + "27": "palette of electric pinks, purples, and blues" +} \ No newline at end of file diff --git a/dreambooth/settings/style.json b/dreambooth/settings/style.json new file mode 100644 index 0000000..2db5f78 --- /dev/null +++ b/dreambooth/settings/style.json @@ -0,0 +1,30 @@ +{ + "00": "neon, glowing, and vibrant", + "01": "vibrant impressionistic", + "02": "whimsical, expressive, and artistic", + "03": "monochrome", + "04": "whimsical and dreamy", + "05": "ornate, illustrative, and vintage", + "06": "red cut-paper art", + "07": "a digital illustration, warm, nostalgic, and harmonious", + "08": "geometric, textured paper craft", + "09": "watercolor, vintage, soft-focus, and dreamy", + "10": "vintage, retro, and nostalgic", + "11": "artistic, illustrative, and detailed", + "12": "blocky, geometric, and digital", + "13": "traditional Chinese ink wash", + "14": "black-and-white illustrative", + "15": "vibrant neon, abstract urban, and dynamic graffiti", + "16": "pixel art", + "17": "watercolor", + "18": "Adorable, Simplified, and Cartoonish", + "19": "pixel art, cubist, and mosaic", + "20": "detailed fantasy illustration", + "21": "Paper Art, Cut-Out, and Collage", + "22": "vintage, hand-drawn, and illustrative", + "23": "monochrome, grayscale, and black-and-white", + "24": "whimsical, playful, and vibrant", + "25": "pixel art", + "26": "geometric paper art", + "27": "retro-futuristic, synthwave, and vibrant neon" +} \ No newline at end of file diff --git a/dreambooth/settings/texture.json b/dreambooth/settings/texture.json new file mode 100644 index 0000000..84b8857 --- /dev/null +++ b/dreambooth/settings/texture.json @@ -0,0 +1,30 @@ +{ + "00": "abstract, digital, and geometric", + "01": "thick brushstrokes, impasto technique, and pixelation", + "02": "detailed, handcrafted, and tactile", + "03": "intricate line work and detailed patterns", + "04": "soft, fluffy, and ethereal clouds", + "05": "swirling patterns, intricate details, and subtle shading", + "06": "intricate line work and detailed patterns", + "07": "that emphasizes sketch-like lines and soft shading", + "08": "intricate, layered paper cuts", + "09": "watercolor, pastel blending, and diffused edges", + "10": "grunge, distressed, and painted brushstrokes", + "11": "digital painting, smooth blending, and vibrant outline", + "12": "pixelated, mosaic-like, and volumetric", + "13": "fluid brushstrokes, delicate gradients, and ethereal blending", + "14": "intricate line work and shading", + "15": "bold outlines, intense saturation, and fluid brushstrokes", + "16": "mosaic, gradient, and detail-oriented rendering", + "17": "soft brushstrokes, layered washes, and fluid blending", + "18": "Sketch-like, Soft Blending, and Pencil Shading", + "19": "blocky, geometric, and segmented", + "20": "intricate line work, depth shading, and dynamic contrasts", + "21": "Layered, Detailed, and Intricate", + "22": "pencil shading, smooth blending, and detailed linework", + "23": "sketch-like, detailed line work, and hand-drawn", + "24": "glossy, smooth, and translucent", + "25": "retro video game graphics, mosaic, grid-like, and blocky", + "26": "clean and precise folds", + "27": "smooth gradients, dynamic reflections, and glowing highlights" +} \ No newline at end of file diff --git a/dreambooth/test_all.sh b/dreambooth/test_all.sh new file mode 100644 index 0000000..59b0be4 --- /dev/null +++ b/dreambooth/test_all.sh @@ -0,0 +1,6 @@ +#!/bin/bash +export HF_ENDPOINT="https://hf-mirror.com" +export HF_HOME="/home/user1/jittor2024/JDiffusion/cached_path" + +COMMAND="python run_all.py" +eval $COMMAND & \ No newline at end of file diff --git a/dreambooth/train.py b/dreambooth/train.py new file mode 100644 index 0000000..74887a9 --- /dev/null +++ b/dreambooth/train.py @@ -0,0 +1,743 @@ +#!/usr/bin/env python +# coding=utf-8 +# Copyright 2024 The HuggingFace Inc. team. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and + +import jittor as jt + +jt.flags.use_rocm = 1 +import jittor.nn as nn +import argparse +import copy +import logging +import math +import os +import warnings +from pathlib import Path + +import numpy as np +import transformers +from peft import LoraConfig +from peft.utils import get_peft_model_state_dict +from PIL import Image +from PIL.ImageOps import exif_transpose +from jittor import transform +from jittor.compatibility.optim import AdamW +from jittor.compatibility.utils.data import Dataset, DataLoader +from tqdm.auto import tqdm +from transformers import AutoTokenizer, PretrainedConfig + +import diffusers +from JDiffusion import ( + AutoencoderKL, + UNet2DConditionModel, +) +from diffusers import DDPMScheduler +from diffusers.loaders import LoraLoaderMixin +from diffusers.optimization import get_scheduler +from diffusers.utils import ( + convert_state_dict_to_diffusers, +) + + +def import_model_class_from_model_name_or_path(pretrained_model_name_or_path: str, revision: str): + text_encoder_config = PretrainedConfig.from_pretrained( + pretrained_model_name_or_path, + subfolder="text_encoder", + revision=revision, + ) + model_class = text_encoder_config.architectures[0] + + if model_class == "CLIPTextModel": + from transformers import CLIPTextModel + return CLIPTextModel + elif model_class == "T5EncoderModel": + from transformers import T5EncoderModel + return T5EncoderModel + else: + raise ValueError(f"{model_class} is not supported.") + + +def parse_args(input_args=None): + parser = argparse.ArgumentParser(description="Simple example of a training script.") + parser.add_argument( + "--num_process", + type=int, + default=1 + ) + parser.add_argument( + "--pretrained_model_name_or_path", + type=str, + default=None, + required=True, + help="Path to pretrained model or model identifier from huggingface.co/models.", + ) + parser.add_argument( + "--revision", + type=str, + default=None, + required=False, + help="Revision of pretrained model identifier from huggingface.co/models.", + ) + parser.add_argument( + "--variant", + type=str, + default=None, + help="Variant of the model files of the pretrained model identifier from huggingface.co/models, 'e.g.' fp16", + ) + parser.add_argument( + "--tokenizer_name", + type=str, + default=None, + help="Pretrained tokenizer name or path if not the same as model_name", + ) + parser.add_argument( + "--instance_data_dir", + type=str, + default=None, + required=True, + help="A folder containing the training data of instance images.", + ) + parser.add_argument( + "--class_data_dir", + type=str, + default=None, + required=False, + help="A folder containing the training data of class images.", + ) + parser.add_argument( + "--instance_prompt", + type=str, + default=None, + required=True, + help="The prompt with identifier specifying the instance", + ) + parser.add_argument( + "--class_prompt", + type=str, + default=None, + help="The prompt to specify images in the same class as provided instance images.", + ) + parser.add_argument( + "--with_prior_preservation", + default=False, + action="store_true", + help="Flag to add prior preservation loss.", + ) + parser.add_argument("--prior_loss_weight", type=float, default=1.0, help="The weight of prior preservation loss.") + parser.add_argument( + "--num_class_images", + type=int, + default=100, + help=( + "Minimal class images for prior preservation loss. If there are not enough images already present in" + " class_data_dir, additional images will be sampled with class_prompt." + ), + ) + parser.add_argument( + "--output_dir", + type=str, + default="lora-dreambooth-model", + help="The output directory where the model predictions and checkpoints will be written.", + ) + parser.add_argument("--seed", type=int, default=None, help="A seed for reproducible training.") + parser.add_argument( + "--resolution", + type=int, + default=512, + help=( + "The resolution for input images, all the images in the train/validation dataset will be resized to this" + " resolution" + ), + ) + parser.add_argument( + "--center_crop", + default=False, + action="store_true", + help=( + "Whether to center crop the input images to the resolution. If not set, the images will be randomly" + " cropped. The images will be resized to the resolution first before cropping." + ), + ) + parser.add_argument( + "--train_batch_size", type=int, default=5, help="Batch size (per device) for the training dataloader." + ) + parser.add_argument( + "--sample_batch_size", type=int, default=4, help="Batch size (per device) for sampling images." + ) + parser.add_argument("--num_train_epochs", type=int, default=1) + parser.add_argument( + "--max_train_steps", + type=int, + default=None, + help="Total number of training steps to perform. If provided, overrides num_train_epochs.", + ) + parser.add_argument( + "--gradient_accumulation_steps", + type=int, + default=1, + help="Number of updates steps to accumulate before performing a backward/update pass.", + ) + parser.add_argument( + "--gradient_checkpointing", + action="store_true", + help="Whether or not to use gradient checkpointing to save memory at the expense of slower backward pass.", + ) + parser.add_argument( + "--learning_rate", + type=float, + default=5e-4, + help="Initial learning rate (after the potential warmup period) to use.", + ) + parser.add_argument( + "--scale_lr", + action="store_true", + default=False, + help="Scale the learning rate by the number of GPUs, gradient accumulation steps, and batch size.", + ) + parser.add_argument( + "--lr_scheduler", + type=str, + default="constant", + help=( + 'The scheduler type to use. Choose between ["linear", "cosine", "cosine_with_restarts", "polynomial",' + ' "constant", "constant_with_warmup"]' + ), + ) + parser.add_argument( + "--lr_warmup_steps", type=int, default=500, help="Number of steps for the warmup in the lr scheduler." + ) + parser.add_argument( + "--lr_num_cycles", + type=int, + default=1, + help="Number of hard resets of the lr in cosine_with_restarts scheduler.", + ) + parser.add_argument("--lr_power", type=float, default=1.0, help="Power factor of the polynomial scheduler.") + parser.add_argument( + "--dataloader_num_workers", + type=int, + default=0, + help=( + "Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process." + ), + ) + parser.add_argument("--adam_beta1", type=float, default=0.9, help="The beta1 parameter for the Adam optimizer.") + parser.add_argument("--adam_beta2", type=float, default=0.999, help="The beta2 parameter for the Adam optimizer.") + parser.add_argument("--adam_weight_decay", type=float, default=1e-2, help="Weight decay to use.") + parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer") + parser.add_argument("--max_grad_norm", default=1.0, type=float, help="Max gradient norm.") + parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.") + parser.add_argument( + "--tokenizer_max_length", + type=int, + default=None, + required=False, + help="The maximum length of the tokenizer. If not set, will default to the tokenizer's max length.", + ) + parser.add_argument( + "--text_encoder_use_attention_mask", + action="store_true", + required=False, + help="Whether to use attention mask for the text encoder", + ) + parser.add_argument( + "--validation_images", + required=False, + default=None, + nargs="+", + help="Optional set of images to use for validation. Used when the target pipeline takes an initial image as input such as when training image variation or superresolution.", + ) + parser.add_argument( + "--class_labels_conditioning", + required=False, + default=None, + help="The optional `class_label` conditioning to pass to the unet, available values are `timesteps`.", + ) + parser.add_argument( + "--rank", + type=int, + default=4, + help=("The dimension of the LoRA update matrices."), + ) + parser.add_argument( + "--checkpoint_save_steps", + type=int, + default=500, + help="Frequency number of saving checkpoint steps to perform.", + ) + parser.add_argument( + "--checkpoint_save_epochs", + type=int, + default=50, + help="Frequency number of saving checkpoint steps to perform.", + ) + + if input_args is not None: + args = parser.parse_args(input_args) + else: + args = parser.parse_args() + + # logger is not available yet + if args.class_data_dir is not None: + warnings.warn("You need not use --class_data_dir without --with_prior_preservation.") + if args.class_prompt is not None: + warnings.warn("You need not use --class_prompt without --with_prior_preservation.") + + return args + + +class DreamBoothDataset(Dataset): + """ + A dataset to prepare the instance and class images with the prompts for fine-tuning the model. + It pre-processes the images and the tokenizes prompts. + """ + + def __init__( + self, + instance_data_root, + instance_prompt, + tokenizer, + class_data_root=None, + class_prompt=None, + class_num=None, + size=512, + center_crop=False, + encoder_hidden_states=None, + class_prompt_encoder_hidden_states=None, + tokenizer_max_length=None, + ): + self.size = size + self.center_crop = center_crop + self.tokenizer = tokenizer + self.encoder_hidden_states = encoder_hidden_states + self.class_prompt_encoder_hidden_states = class_prompt_encoder_hidden_states + self.tokenizer_max_length = tokenizer_max_length + + self.instance_data_root = Path(instance_data_root) + if not self.instance_data_root.exists(): + raise ValueError("Instance images root doesn't exists.") + + self.instance_images_path = list(Path(instance_data_root).iterdir()) + self.num_instance_images = len(self.instance_images_path) + self.instance_prompt = instance_prompt + self._length = self.num_instance_images + + if class_data_root is not None: + self.class_data_root = Path(class_data_root) + self.class_data_root.mkdir(parents=True, exist_ok=True) + self.class_images_path = list(self.class_data_root.iterdir()) + if class_num is not None: + self.num_class_images = min(len(self.class_images_path), class_num) + else: + self.num_class_images = len(self.class_images_path) + self._length = max(self.num_class_images, self.num_instance_images) + self.class_prompt = class_prompt + else: + self.class_data_root = None + + self.image_transforms = transform.Compose( + [ + transform.Resize(size), + transform.CenterCrop(size) if center_crop else transform.RandomCrop(size), + transform.ToTensor(), + transform.ImageNormalize([0.5], [0.5]), + ] + ) + + def __len__(self): + return self._length + + def __getitem__(self, index): + example = {} + instance_image = Image.open(self.instance_images_path[index % self.num_instance_images]) + instance_image = exif_transpose(instance_image) + prompt = "A photo of {}".format( + str(self.instance_images_path[index % self.num_instance_images]). + split("/")[-1].split(".")[-2].replace("_", " ")) + self.instance_prompt + print("Prompt:", prompt) + + if not instance_image.mode == "RGB": + instance_image = instance_image.convert("RGB") + example["instance_images"] = self.image_transforms(instance_image) + + if self.encoder_hidden_states is not None: + example["instance_prompt_ids"] = self.encoder_hidden_states + else: + text_inputs = tokenize_prompt( + self.tokenizer, prompt, tokenizer_max_length=self.tokenizer_max_length + ) + example["instance_prompt_ids"] = text_inputs.input_ids + example["instance_attention_mask"] = text_inputs.attention_mask + + if self.class_data_root: + class_image = Image.open(self.class_images_path[index % self.num_class_images]) + class_image = exif_transpose(class_image) + + if not class_image.mode == "RGB": + class_image = class_image.convert("RGB") + example["class_images"] = self.image_transforms(class_image) + + if self.class_prompt_encoder_hidden_states is not None: + example["class_prompt_ids"] = self.class_prompt_encoder_hidden_states + else: + class_text_inputs = tokenize_prompt( + self.tokenizer, self.class_prompt, tokenizer_max_length=self.tokenizer_max_length + ) + example["class_prompt_ids"] = class_text_inputs.input_ids + example["class_attention_mask"] = class_text_inputs.attention_mask + + return example + + +def collate_fn(examples, with_prior_preservation=False): + has_attention_mask = "instance_attention_mask" in examples[0] + + input_ids = [example["instance_prompt_ids"] for example in examples] + pixel_values = [example["instance_images"] for example in examples] + + if has_attention_mask: + attention_mask = [example["instance_attention_mask"] for example in examples] + + pixel_values = jt.stack(pixel_values) + pixel_values = pixel_values.float() + + input_ids = jt.cat(input_ids, dim=0) + + batch = { + "input_ids": input_ids, + "pixel_values": pixel_values, + } + + if has_attention_mask: + batch["attention_mask"] = attention_mask + + return batch + + +class PromptDataset(Dataset): + "A simple dataset to prepare the prompts to generate class images on multiple GPUs." + + def __init__(self, prompt, num_samples): + self.prompt = prompt + self.num_samples = num_samples + + def __len__(self): + return self.num_samples + + def __getitem__(self, index): + example = {} + example["prompt"] = self.prompt + example["index"] = index + return example + + +def tokenize_prompt(tokenizer, prompt, tokenizer_max_length=None): + if tokenizer_max_length is not None: + max_length = tokenizer_max_length + else: + max_length = tokenizer.model_max_length + + text_inputs = tokenizer( + prompt, + truncation=True, + padding="max_length", + max_length=max_length, + return_tensors="pt", + ) + + return text_inputs + + +def encode_prompt(text_encoder, input_ids, attention_mask, text_encoder_use_attention_mask=None): + text_input_ids = input_ids.to(text_encoder.device) + + if text_encoder_use_attention_mask: + attention_mask = attention_mask.to(text_encoder.device) + else: + attention_mask = None + + prompt_embeds = text_encoder( + text_input_ids, + attention_mask=attention_mask, + return_dict=False, + ) + prompt_embeds = prompt_embeds[0] + + return prompt_embeds + + +def main(args): + # Make one log on every process with the configuration for debugging. + logging.basicConfig( + format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", + datefmt="%m/%d/%Y %H:%M:%S", + level=logging.INFO, + ) + transformers.utils.logging.set_verbosity_warning() + diffusers.utils.logging.set_verbosity_info() + + # Handle the repository creation + # if args.output_dir is not None: + # os.makedirs(args.output_dir, exist_ok=True) + + # Load the tokenizer + if args.tokenizer_name: + tokenizer = AutoTokenizer.from_pretrained(args.tokenizer_name, revision=args.revision, use_fast=False) + elif args.pretrained_model_name_or_path: + tokenizer = AutoTokenizer.from_pretrained( + args.pretrained_model_name_or_path, + subfolder="tokenizer", + revision=args.revision, + use_fast=False, + ) + + # import correct text encoder class + text_encoder_cls = import_model_class_from_model_name_or_path(args.pretrained_model_name_or_path, args.revision) + + # Load scheduler and models + noise_scheduler = DDPMScheduler.from_pretrained(args.pretrained_model_name_or_path, subfolder="scheduler") + text_encoder = text_encoder_cls.from_pretrained( + args.pretrained_model_name_or_path, subfolder="text_encoder", revision=args.revision + ) + vae = AutoencoderKL.from_pretrained( + args.pretrained_model_name_or_path, subfolder="vae", revision=args.revision + ) + + unet = UNet2DConditionModel.from_pretrained( + args.pretrained_model_name_or_path, subfolder="unet", revision=args.revision + ) + + # We only train the additional adapter LoRA layers + # if vae is not None: + # vae.requires_grad_(False) + # text_encoder.requires_grad_(False) + # unet.requires_grad_(False) + + # For mixed precision training we cast all non-trainable weights (vae, non-lora text_encoder and non-lora unet) to half-precision + # as these weights are only used for inference, keeping weights in full precision is not required. + weight_dtype = jt.float32 + + # Move unet, vae and text_encoder to device and cast to weight_dtype + # unet.to("cuda", dtype=weight_dtype) + # if vae is not None: + # vae.to("cuda", dtype=weight_dtype) + # text_encoder.to("cuda", dtype=weight_dtype) + + for name, param in unet.named_parameters(): + assert param.requires_grad == False, name + # now we will add new LoRA weights to the attention layers + unet_lora_config = LoraConfig( + r=args.rank, + lora_alpha=args.rank, + init_lora_weights="gaussian", + target_modules=["to_k", "to_q", "to_v", "to_out.0", "add_k_proj", "add_v_proj"], + ) + unet.add_adapter(unet_lora_config) + + # Optimizer creation + + optimizer = AdamW( + list(unet.parameters()), + lr=args.learning_rate, + betas=(args.adam_beta1, args.adam_beta2), + weight_decay=args.adam_weight_decay, + eps=args.adam_epsilon, + ) + + pre_computed_encoder_hidden_states = None + pre_computed_class_prompt_encoder_hidden_states = None + + # Dataset and DataLoaders creation: + train_dataset = DreamBoothDataset( + instance_data_root=args.instance_data_dir, + instance_prompt=args.instance_prompt, + class_data_root=args.class_data_dir if args.with_prior_preservation else None, + class_prompt=args.class_prompt, + class_num=args.num_class_images, + tokenizer=tokenizer, + size=args.resolution, + center_crop=args.center_crop, + encoder_hidden_states=pre_computed_encoder_hidden_states, + class_prompt_encoder_hidden_states=pre_computed_class_prompt_encoder_hidden_states, + tokenizer_max_length=args.tokenizer_max_length, + ) + + train_dataloader = DataLoader( + train_dataset, + batch_size=args.train_batch_size, + shuffle=True, + collate_fn=lambda examples: collate_fn(examples, False), + num_workers=args.dataloader_num_workers, + ) + + # Scheduler and math around the number of training steps. + overrode_max_train_steps = False + num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps) + if args.max_train_steps is None: + args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch + overrode_max_train_steps = True + + lr_scheduler = get_scheduler( + args.lr_scheduler, + optimizer=optimizer, + num_warmup_steps=args.lr_warmup_steps * args.num_process, + num_training_steps=args.max_train_steps * args.num_process, + num_cycles=args.lr_num_cycles, + power=args.lr_power, + ) + + # We need to recalculate our total training steps as the size of the training dataloader may have changed. + num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps) + if overrode_max_train_steps: + args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch + # Afterwards we recalculate our number of training epochs + args.num_train_epochs = math.ceil(args.max_train_steps / num_update_steps_per_epoch) + + # We need to initialize the trackers we use, and also store our configuration. + # The trackers initializes automatically on the main process. + tracker_config = vars(copy.deepcopy(args)) + tracker_config.pop("validation_images") + + # Train! + total_batch_size = args.train_batch_size * args.num_process * args.gradient_accumulation_steps + + print("***** Running training *****") + print(f" Num examples = {len(train_dataset)}") + print(f" Num batches each epoch = {len(train_dataloader)}") + print(f" Num Epochs = {args.num_train_epochs}") + print(f" Instantaneous batch size per device = {args.train_batch_size}") + print(f" Total train batch size (w. parallel, distributed & accumulation) = {total_batch_size}") + print(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}") + print(f" Total optimization steps = {args.max_train_steps}") + global_step = 0 + first_epoch = 0 + + initial_global_step = 0 + + progress_bar = tqdm( + range(0, args.max_train_steps), + initial=initial_global_step, + desc="Steps", + # Only show the progress bar once on each machine. + disable=False, + ) + + losses_list, lr_list = [], [] + for epoch in range(first_epoch, args.num_train_epochs): + for step, batch in enumerate(train_dataloader): + pixel_values = batch["pixel_values"].to(dtype=weight_dtype) + + # Convert images to latent space + model_input = vae.encode(pixel_values).latent_dist.sample() + model_input = model_input * vae.config.scaling_factor + + # Sample noise that we'll add to the latents + noise = jt.randn_like(model_input) + bsz, channels, height, width = model_input.shape + # Sample a random timestep for each image + timesteps = jt.randint( + 0, noise_scheduler.config.num_train_timesteps, (bsz,), + ).to(device=model_input.device) + timesteps = timesteps.long() + + # Add noise to the model input according to the noise magnitude at each timestep + # (this is the forward diffusion process) + noisy_model_input = noise_scheduler.add_noise(model_input, noise, timesteps) + + # Get the text embedding for conditioning + encoder_hidden_states = encode_prompt( + text_encoder, + batch["input_ids"], + batch["attention_mask"], + text_encoder_use_attention_mask=args.text_encoder_use_attention_mask, + ) + + if unet.config.in_channels == channels * 2: + noisy_model_input = jt.cat([noisy_model_input, noisy_model_input], dim=1) + + if args.class_labels_conditioning == "timesteps": + class_labels = timesteps + else: + class_labels = None + + # Predict the noise residual + model_pred = unet( + noisy_model_input, + timesteps, + encoder_hidden_states, + class_labels=class_labels, + return_dict=False, + )[0] + + # if model predicts variance, throw away the prediction. we will only train on the + # simplified training objective. This means that all schedulers using the fine tuned + # model must be configured to use one of the fixed variance variance types. + if model_pred.shape[1] == 6: + model_pred, _ = jt.chunk(model_pred, 2, dim=1) + + # Get the target for loss depending on the prediction type + if noise_scheduler.config.prediction_type == "epsilon": + target = noise + elif noise_scheduler.config.prediction_type == "v_prediction": + target = noise_scheduler.get_velocity(model_input, noise, timesteps) + else: + raise ValueError(f"Unknown prediction type {noise_scheduler.config.prediction_type}") + + loss = nn.mse_loss(model_pred, target) + loss.backward() + + optimizer.step() + lr_scheduler.step() + optimizer.zero_grad() + + progress_bar.update(1) + global_step += 1 + + logs = {"loss": loss.detach().item()} + losses_list.append(loss.detach().item()) + lr_list.append(lr_scheduler.get_last_lr()[0]) + # logs = {"loss": loss.detach().item(), "lr": lr_scheduler.get_last_lr()[0]} + progress_bar.set_postfix(**logs) + + if global_step >= args.max_train_steps: + break + + if (epoch + 1) % args.checkpoint_save_epochs == 0: + # Save the lora layers + unet = unet.to(jt.float32) + unet_lora_state_dict = convert_state_dict_to_diffusers(get_peft_model_state_dict(unet)) + + base_dir, style_dir = os.path.split(args.output_dir) + style_output_dir = os.path.join(base_dir + f"_{epoch + 1}epoch", style_dir) + print("style_output_dir:", style_output_dir) + if style_output_dir is not None: + os.makedirs(style_output_dir, exist_ok=True) + text_encoder_state_dict = None + LoraLoaderMixin.save_lora_weights( + save_directory=style_output_dir, + unet_lora_layers=unet_lora_state_dict, + text_encoder_lora_layers=text_encoder_state_dict, + safe_serialization=False + ) + + record_dir = "/".join(args.output_dir.split("/")[:-2]) + style_number = args.output_dir.split("_")[-1] + print(f"record_dir: {record_dir}") + np.save(os.path.join(record_dir, f'losses_{style_number}.npy'), np.array(losses_list)) + np.save(os.path.join(record_dir, f'lr_{style_number}.npy'), np.array(lr_list)) + + +if __name__ == "__main__": + args = parse_args() + main(args) diff --git a/dreambooth/train_all.sh b/dreambooth/train_all.sh new file mode 100644 index 0000000..792c239 --- /dev/null +++ b/dreambooth/train_all.sh @@ -0,0 +1,62 @@ +#!/bin/bash +export HF_ENDPOINT="https://hf-mirror.com" +export HF_HOME="/home/user1/jittor2024/JDiffusion/cached_path" + +root="/home/user1/jittor2024/jittor-B-commit" +save_root="${root}/dreambooth/results/prompt_v1_cosine_test" +style_file="${root}/dreambooth/settings/style.json" +texture_file="${root}/dreambooth/settings/texture.json" +color_file="${root}/dreambooth/settings/color.json" + +MODEL_NAME="stabilityai/stable-diffusion-2-1" +BASE_INSTANCE_DIR="${root}/B" +OUTPUT_DIR_PREFIX="${save_root}/style/style_" +RESOLUTION=512 +TRAIN_BATCH_SIZE=1 +GRADIENT_ACCUMULATION_STEPS=1 +CHECKPOINTING_EPOCHS=25 +LEARNING_RATE=1e-4 +LR_SCHEDULER="cosine" +LR_WARMUP_STEPS=0 +MAX_TRAIN_EPOCHS=500 +SEED=0 +GPU_COUNT=1 +MAX_NUM=27 + +for ((folder_number = 0; folder_number <= $MAX_NUM; folder_number+=$GPU_COUNT)); do + for ((gpu_id = 0; gpu_id < GPU_COUNT; gpu_id++)); do + current_folder_number=$((folder_number + gpu_id)) + if [ $current_folder_number -gt $MAX_NUM ]; then + break + fi + key=$(printf "%02d" $current_folder_number) + style_prompt=$(python read_json.py "$style_file" "$key") + texture_prompt=$(python read_json.py "$texture_file" "$key") + color_prompt=$(python read_json.py "$color_file" "$key") + INSTANCE_DIR="${BASE_INSTANCE_DIR}/$(printf "%02d" $current_folder_number)/images" + OUTPUT_DIR="${OUTPUT_DIR_PREFIX}$(printf "%02d" $current_folder_number)" + CUDA_VISIBLE_DEVICES=$gpu_id +# CUDA_VISIBLE_DEVICES="1,0" +# PROMPT=$(printf "style_%02d" $current_folder_number) + PROMPT=" in $style_prompt style, with a texture of $texture_prompt and with a color style of $color_prompt." + echo "current_folder_number: $current_folder_number, PROMPT: $PROMPT" + + COMMAND="CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES python train.py \ + --pretrained_model_name_or_path=$MODEL_NAME \ + --instance_data_dir=$INSTANCE_DIR \ + --output_dir=$OUTPUT_DIR \ + --instance_prompt='$PROMPT' \ + --resolution=$RESOLUTION \ + --train_batch_size=$TRAIN_BATCH_SIZE \ + --gradient_accumulation_steps=$GRADIENT_ACCUMULATION_STEPS \ + --learning_rate=$LEARNING_RATE \ + --lr_scheduler=$LR_SCHEDULER \ + --lr_warmup_steps=$LR_WARMUP_STEPS \ + --num_train_epochs=$MAX_TRAIN_EPOCHS \ + --seed=$SEED \ + --checkpoint_save_epochs=$CHECKPOINTING_EPOCHS" + eval $COMMAND & + sleep 3 + done + wait +done