Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,173 +74,6 @@ clevr_model.to(device)
|
|
| 74 |
clevr_model.load_state_dict(th.load(download_model('clevr_pos'), device))
|
| 75 |
device = th.device('cpu' if not th.cuda.is_available() else 'cuda')
|
| 76 |
|
| 77 |
-
# init stable diffusion model
|
| 78 |
-
pipe = ComposableStableDiffusionPipeline.from_pretrained(
|
| 79 |
-
"CompVis/stable-diffusion-v1-4",
|
| 80 |
-
).to(device)
|
| 81 |
-
|
| 82 |
-
pipe.safety_checker = None
|
| 83 |
-
|
| 84 |
-
# create model for CLEVR Objects
|
| 85 |
-
clevr_options = model_and_diffusion_defaults_for_clevr()
|
| 86 |
-
|
| 87 |
-
flags = {
|
| 88 |
-
"image_size": 128,
|
| 89 |
-
"num_channels": 192,
|
| 90 |
-
"num_res_blocks": 2,
|
| 91 |
-
"learn_sigma": True,
|
| 92 |
-
"use_scale_shift_norm": False,
|
| 93 |
-
"raw_unet": True,
|
| 94 |
-
"noise_schedule": "squaredcos_cap_v2",
|
| 95 |
-
"rescale_learned_sigmas": False,
|
| 96 |
-
"rescale_timesteps": False,
|
| 97 |
-
"num_classes": '2',
|
| 98 |
-
"dataset": "clevr_pos",
|
| 99 |
-
"use_fp16": has_cuda,
|
| 100 |
-
"timestep_respacing": '100'
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
for key, val in flags.items():
|
| 104 |
-
clevr_options[key] = val
|
| 105 |
-
|
| 106 |
-
clevr_model, clevr_diffusion = create_model_and_diffusion_for_clevr(**clevr_options)
|
| 107 |
-
clevr_model.eval()
|
| 108 |
-
if has_cuda:
|
| 109 |
-
clevr_model.convert_to_fp16()
|
| 110 |
-
|
| 111 |
-
clevr_model.to(device)
|
| 112 |
-
clevr_model.load_state_dict(th.load(download_model('clevr_pos'), device))
|
| 113 |
-
print('total clevr_pos parameters', sum(x.numel() for x in clevr_model.parameters()))
|
| 114 |
-
|
| 115 |
-
print('creating base model...')
|
| 116 |
-
base_name = 'base40M-textvec'
|
| 117 |
-
base_model = model_from_config(MODEL_CONFIGS[base_name], device)
|
| 118 |
-
base_model.eval()
|
| 119 |
-
base_diffusion = diffusion_from_config(DIFFUSION_CONFIGS[base_name])
|
| 120 |
-
|
| 121 |
-
print('creating upsample model...')
|
| 122 |
-
upsampler_model = model_from_config(MODEL_CONFIGS['upsample'], device)
|
| 123 |
-
upsampler_model.eval()
|
| 124 |
-
upsampler_diffusion = diffusion_from_config(DIFFUSION_CONFIGS['upsample'])
|
| 125 |
-
|
| 126 |
-
print('downloading base checkpoint...')
|
| 127 |
-
base_model.load_state_dict(load_checkpoint(base_name, device))
|
| 128 |
-
|
| 129 |
-
print('downloading upsampler checkpoint...')
|
| 130 |
-
upsampler_model.load_state_dict(load_checkpoint('upsample', device))
|
| 131 |
-
|
| 132 |
-
print('creating SDF model...')
|
| 133 |
-
name = 'sdf'
|
| 134 |
-
model = model_from_config(MODEL_CONFIGS[name], device)
|
| 135 |
-
model.eval()
|
| 136 |
-
|
| 137 |
-
print('loading SDF model...')
|
| 138 |
-
model.load_state_dict(load_checkpoint(name, device))
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
def compose_pointe(prompt, weights):
|
| 142 |
-
weight_list = [float(x.strip()) for x in weights.split('|')]
|
| 143 |
-
sampler = PointCloudSampler(
|
| 144 |
-
device=device,
|
| 145 |
-
models=[base_model, upsampler_model],
|
| 146 |
-
diffusions=[base_diffusion, upsampler_diffusion],
|
| 147 |
-
num_points=[1024, 4096 - 1024],
|
| 148 |
-
aux_channels=['R', 'G', 'B'],
|
| 149 |
-
guidance_scale=[weight_list, 0.0],
|
| 150 |
-
model_kwargs_key_filter=('texts', ''), # Do not condition the upsampler at all
|
| 151 |
-
)
|
| 152 |
-
|
| 153 |
-
def generate_pcd(prompt_list):
|
| 154 |
-
# Produce a sample from the model.
|
| 155 |
-
samples = None
|
| 156 |
-
for x in tqdm(sampler.sample_batch_progressive(batch_size=1, model_kwargs=dict(texts=prompt_list))):
|
| 157 |
-
samples = x
|
| 158 |
-
return samples
|
| 159 |
-
|
| 160 |
-
def generate_fig(samples):
|
| 161 |
-
pc = sampler.output_to_point_clouds(samples)[0]
|
| 162 |
-
return pc
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
# has_cuda = th.cuda.is_available()
|
| 166 |
-
device = th.device('cpu' if not th.cuda.is_available() else 'cuda')
|
| 167 |
-
|
| 168 |
-
# init stable diffusion model
|
| 169 |
-
pipe = ComposableStableDiffusionPipeline.from_pretrained(
|
| 170 |
-
"CompVis/stable-diffusion-v1-4",
|
| 171 |
-
).to(device)
|
| 172 |
-
|
| 173 |
-
pipe.safety_checker = None
|
| 174 |
-
|
| 175 |
-
# create model for CLEVR Objects
|
| 176 |
-
clevr_options = model_and_diffusion_defaults_for_clevr()
|
| 177 |
-
|
| 178 |
-
flags = {
|
| 179 |
-
"image_size": 128,
|
| 180 |
-
"num_channels": 192,
|
| 181 |
-
"num_res_blocks": 2,
|
| 182 |
-
"learn_sigma": True,
|
| 183 |
-
"use_scale_shift_norm": False,
|
| 184 |
-
"raw_unet": True,
|
| 185 |
-
"noise_schedule": "squaredcos_cap_v2",
|
| 186 |
-
"rescale_learned_sigmas": False,
|
| 187 |
-
"rescale_timesteps": False,
|
| 188 |
-
"num_classes": '2',
|
| 189 |
-
"dataset": "clevr_pos",
|
| 190 |
-
"use_fp16": has_cuda,
|
| 191 |
-
"timestep_respacing": '100'
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
-
for key, val in flags.items():
|
| 195 |
-
clevr_options[key] = val
|
| 196 |
-
|
| 197 |
-
clevr_model, clevr_diffusion = create_model_and_diffusion_for_clevr(**clevr_options)
|
| 198 |
-
clevr_model.eval()
|
| 199 |
-
if has_cuda:
|
| 200 |
-
clevr_model.convert_to_fp16()
|
| 201 |
-
|
| 202 |
-
clevr_model.to(device)
|
| 203 |
-
clevr_model.load_state_dict(th.load(download_model('clevr_pos'), device))
|
| 204 |
-
device = th.device('cpu' if not th.cuda.is_available() else 'cuda')
|
| 205 |
-
|
| 206 |
-
# init stable diffusion model
|
| 207 |
-
pipe = ComposableStableDiffusionPipeline.from_pretrained(
|
| 208 |
-
"CompVis/stable-diffusion-v1-4",
|
| 209 |
-
).to(device)
|
| 210 |
-
|
| 211 |
-
pipe.safety_checker = None
|
| 212 |
-
|
| 213 |
-
# create model for CLEVR Objects
|
| 214 |
-
clevr_options = model_and_diffusion_defaults_for_clevr()
|
| 215 |
-
|
| 216 |
-
flags = {
|
| 217 |
-
"image_size": 128,
|
| 218 |
-
"num_channels": 192,
|
| 219 |
-
"num_res_blocks": 2,
|
| 220 |
-
"learn_sigma": True,
|
| 221 |
-
"use_scale_shift_norm": False,
|
| 222 |
-
"raw_unet": True,
|
| 223 |
-
"noise_schedule": "squaredcos_cap_v2",
|
| 224 |
-
"rescale_learned_sigmas": False,
|
| 225 |
-
"rescale_timesteps": False,
|
| 226 |
-
"num_classes": '2',
|
| 227 |
-
"dataset": "clevr_pos",
|
| 228 |
-
"use_fp16": has_cuda,
|
| 229 |
-
"timestep_respacing": '100'
|
| 230 |
-
}
|
| 231 |
-
|
| 232 |
-
for key, val in flags.items():
|
| 233 |
-
clevr_options[key] = val
|
| 234 |
-
|
| 235 |
-
clevr_model, clevr_diffusion = create_model_and_diffusion_for_clevr(**clevr_options)
|
| 236 |
-
clevr_model.eval()
|
| 237 |
-
if has_cuda:
|
| 238 |
-
clevr_model.convert_to_fp16()
|
| 239 |
-
|
| 240 |
-
clevr_model.to(device)
|
| 241 |
-
clevr_model.load_state_dict(th.load(download_model('clevr_pos'), device))
|
| 242 |
-
print('total clevr_pos parameters', sum(x.numel() for x in clevr_model.parameters()))
|
| 243 |
-
|
| 244 |
print('creating base model...')
|
| 245 |
base_name = 'base40M-textvec'
|
| 246 |
base_model = model_from_config(MODEL_CONFIGS[base_name], device)
|
|
|
|
| 74 |
clevr_model.load_state_dict(th.load(download_model('clevr_pos'), device))
|
| 75 |
device = th.device('cpu' if not th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