Jeremynac commited on
Commit
41a2045
·
1 Parent(s): 7400582

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import torch
3
+ from tqdm.auto import tqdm
4
+
5
+ from point_e.diffusion.configs import DIFFUSION_CONFIGS, diffusion_from_config
6
+ from point_e.diffusion.sampler import PointCloudSampler
7
+ from point_e.models.download import load_checkpoint
8
+ from point_e.models.configs import MODEL_CONFIGS, model_from_config
9
+ from point_e.util.plotting import plot_point_cloud
10
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
11
+
12
+ print('creating base model...')
13
+ base_name = 'base40M' # use base300M or base1B for better results
14
+ base_model = model_from_config(MODEL_CONFIGS[base_name], device)
15
+ base_model.eval()
16
+ base_diffusion = diffusion_from_config(DIFFUSION_CONFIGS[base_name])
17
+
18
+ print('creating upsample model...')
19
+ upsampler_model = model_from_config(MODEL_CONFIGS['upsample'], device)
20
+ upsampler_model.eval()
21
+ upsampler_diffusion = diffusion_from_config(DIFFUSION_CONFIGS['upsample'])
22
+
23
+ print('downloading base checkpoint...')
24
+ base_model.load_state_dict(load_checkpoint(base_name, device))
25
+
26
+ print('downloading upsampler checkpoint...')
27
+ upsampler_model.load_state_dict(load_checkpoint('upsample', device))
28
+ sampler = PointCloudSampler(
29
+ device=device,
30
+ models=[base_model, upsampler_model],
31
+ diffusions=[base_diffusion, upsampler_diffusion],
32
+ num_points=[1024, 4096 - 1024],
33
+ aux_channels=['R', 'G', 'B'],
34
+ guidance_scale=[3.0, 3.0],
35
+ )
36
+ # Load an image to condition on.
37
+ img = Image.open('https://image.pngaaa.com/549/295549-middle.png')
38
+
39
+ # Produce a sample from the model.
40
+ samples = None
41
+ for x in tqdm(sampler.sample_batch_progressive(batch_size=1, model_kwargs=dict(images=[img]))):
42
+ samples = x
43
+ pc = sampler.output_to_point_clouds(samples)[0]
44
+ fig = plot_point_cloud(pc, grid_size=3, fixed_bounds=((-0.75, -0.75, -0.75),(0.75, 0.75, 0.75)))