-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
62 lines (51 loc) · 1.81 KB
/
run.py
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
import asyncio
# import torch.cuda
import torch
from rich.console import Console
from torch.utils.data import DataLoader
from camera_view_generator.camera import CameraDataset
from stable_diffusion_guidance.guidance import StableDiffusionGuidance
from tiny_nerf.nerf import NerfModel, train
# from PIL import Image
console = Console()
async def run(prompt: str):
console.print(
":film_projector: [bold green] Welcome to Tiny DreamFusion :film_projector:"
)
print(f"Training {prompt}...")
device = "cuda" if torch.cuda.is_available() else "cpu"
height = width = 32
# The smaller the images the faster the training and evaluation
batch_size = 8 # If running out of memory reduce this
max_frames = (
5 # Maximum number of images to train with. Lower this to speed up training
)
nb_epochs = 1
console.print(f"Using {max_frames} images and running for {nb_epochs} epochs")
training_dataset = CameraDataset(label="train", samples=128, H=height, W=width)
testing_dataset = CameraDataset(label="test", samples=128, H=height, W=width)
model = NerfModel(hidden_dim=256).to(device)
model_optimizer = torch.optim.Adam(model.parameters(), lr=5e-4)
scheduler = torch.optim.lr_scheduler.MultiStepLR(
model_optimizer, milestones=[2, 4, 8], gamma=0.5
)
data_loader = DataLoader(training_dataset, batch_size=batch_size, shuffle=True)
sd_guidance = StableDiffusionGuidance(prompt)
train(
batch_size,
model,
model_optimizer,
scheduler,
data_loader,
testing_dataset,
guidance=sd_guidance,
nb_epochs=nb_epochs,
device=device,
hn=2,
hf=6,
nb_bins=192,
H=height,
W=width,
)
if __name__ == "__main__":
asyncio.run(run('Delicious hamburger'))