forked from openai/guided-diffusion
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_specific_classes.sh
More file actions
executable file
·132 lines (117 loc) · 3.51 KB
/
Copy pathgenerate_specific_classes.sh
File metadata and controls
executable file
·132 lines (117 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# Generate 512x512 images of specific well-known ImageNet classes
# Based on the example image showing popular animals and objects
cd /home/senum/projects/guided-diffusion/guided-diffusion
echo "🎨 Generating 512×512 images of SPECIFIC classes"
echo "=================================================="
echo ""
# Well-known ImageNet classes (matching your reference image)
# Format: CLASS_ID = Class Name
#
# Row 1: Birds & Dogs
# 9 = Ostrich
# 130 = Flamingo
# 263 = Pembroke Welsh Corgi
# 1 = Goldfish
# 207 = Golden Retriever
# 94 = Hummingbird
#
# Row 2: Wildlife
# 279 = Arctic Fox
# 289 = Snow Leopard
# 323 = Monarch Butterfly
# 367 = Chimpanzee
# 388 = Giant Panda
# 387 = Red Panda (Lesser Panda)
#
# Row 3: Objects & Animals
# 852 = Tennis Ball
# 250 = Siberian Husky
# 609 = Pickup Truck (old style)
# 76 = Spider (Tarantula)
# 92 = Bee Eater (colorful bird)
# 928 = Ice Cream / Trifle
# Define the classes to generate
CLASSES="9,130,263,1,207,94,279,289,323,367,388,387,852,250,609,76,92,928"
NUM_SAMPLES=18
echo "Classes to generate:"
echo " Row 1: Ostrich, Flamingo, Corgi, Goldfish, Golden Retriever, Hummingbird"
echo " Row 2: Arctic Fox, Snow Leopard, Butterfly, Chimpanzee, Giant Panda, Red Panda"
echo " Row 3: Tennis Ball, Husky, Pickup Truck, Spider, Bee Eater, Dessert"
echo ""
echo "Total: $NUM_SAMPLES images"
echo ""
# Create output directory
mkdir -p outputs/specific_classes
python simple_demo.py \
--model_path models/512x512_diffusion.pt \
--classifier_path models/512x512_classifier.pt \
--classifier_scale 4.0 \
--classifier_width 128 \
--classifier_depth 2 \
--classifier_attention_resolutions 32,16,8 \
--attention_resolutions 32,16,8 \
--class_cond True \
--diffusion_steps 1000 \
--dropout 0.0 \
--image_size 512 \
--learn_sigma True \
--noise_schedule linear \
--num_channels 256 \
--num_head_channels 64 \
--num_res_blocks 2 \
--resblock_updown True \
--use_new_attention_order False \
--use_scale_shift_norm True \
--timestep_respacing 250 \
--num_samples $NUM_SAMPLES \
--batch_size 1 \
--classes "$CLASSES" \
--output_dir outputs/specific_classes
echo ""
echo "📸 Converting to PNG images with class names..."
python -c "
import numpy as np
from PIL import Image
import glob
import os
# Class ID to name mapping
CLASS_NAMES = {
9: 'ostrich',
130: 'flamingo',
263: 'corgi',
1: 'goldfish',
207: 'golden_retriever',
94: 'hummingbird',
279: 'arctic_fox',
289: 'snow_leopard',
323: 'monarch_butterfly',
367: 'chimpanzee',
388: 'giant_panda',
387: 'red_panda',
852: 'tennis_ball',
250: 'siberian_husky',
609: 'pickup_truck',
76: 'tarantula',
92: 'bee_eater',
928: 'trifle_dessert',
}
output_dir = 'outputs/specific_classes'
npz_files = glob.glob(f'{output_dir}/samples_*.npz')
latest_file = max(npz_files, key=os.path.getctime)
data = np.load(latest_file)
images = data['arr_0']
labels = data['arr_1'] if 'arr_1' in data.files else None
print(f'Loaded {len(images)} images')
for i, img in enumerate(images):
if labels is not None:
class_id = labels[i]
class_name = CLASS_NAMES.get(class_id, f'class_{class_id}')
save_path = f'{output_dir}/{i+1:02d}_{class_name}.png'
else:
save_path = f'{output_dir}/sample_{i+1:02d}.png'
Image.fromarray(img).save(save_path)
print(f'✓ {save_path}')
"
echo ""
echo "✅ Done! Check outputs/specific_classes/ for named PNG files"