-
Notifications
You must be signed in to change notification settings - Fork 0
/
cartoon_train.py
executable file
·83 lines (72 loc) · 2.73 KB
/
cartoon_train.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import time
from options.train_options import TrainOptions
from data import CreateDataLoader
from models import create_model
from util.visualizer import Visualizer
import numpy as np
if __name__ == '__main__':
opt = TrainOptions().parse()
data_loader = CreateDataLoader(opt)
dataset = data_loader.load_data()
dataset_size = len(data_loader)
print('#training images = %d' % dataset_size)
model = create_model(opt)
#model.initialize(opt)
#visualizer = Visualizer(opt)
for epoch in range(0):
epoch_start_time = time.time()
iter_data_time = time.time()
epoch_iter = 0
print "epoch ",epoch
loss = np.zeros((3))
count = 0;
for i, data in enumerate(dataset):
#print "..."
#iter_start_time = time.time()
#if total_steps % opt.print_freq == 0:
#t_data = iter_start_time - iter_data_time
#visualizer.reset()
#total_steps += opt.batchSize
#epoch_iter += opt.batchSize
model.set_input(data)
model.pre_optimize_parameters()
errors = model.get_current_errors()
print errors["C"].data.cpu().numpy()[0]
loss[0] += errors["C"].data.cpu().numpy()[0]
count += 1
#loss[1] += errors["G"].data.cpu().numpy()[0]
#loss[2] += errors["D"].data.cpu().numpy()[0]
print time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
print loss/count
model.save('latest')
model.save(epoch)
#train cartoon_net
for epoch in range(100):
#epoch_start_time = time.time()
#iter_data_time = time.time()
print "epoch ",epoch
loss = np.zeros((3))
count = 0
for i, data in enumerate(dataset):
#print "..."
#iter_start_time = time.time()
#if total_steps % opt.print_freq == 0:
# t_data = iter_start_time - iter_data_time
#visualizer.reset()
#total_steps += opt.batchSize
#epoch_iter += opt.batchSize
model.set_input(data)
model.optimize_parameters()
errors = model.get_current_errors()
loss[0] += errors["C"].data.cpu().numpy()[0]
loss[1] += errors["G"].data.cpu().numpy()[0]
loss[2] += errors["D"].data.cpu().numpy()[0]
print errors["C"].data.cpu().numpy()[0],\
errors["G"].data.cpu().numpy()[0],\
errors["D"].data.cpu().numpy()[0]
count += 1
print time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
print loss/count
model.save('latest')
model.save(epoch)
model.update_learning_rate()