97aeda2a947c44cdef91d9276c2c38c02f37cda1,train.py,,train_inner_epoch,#,35
Before Change
perm = np.random.permutation(len(train_x))
for i in range(0, len(train_x), cfg.batch_size):
local_perm = perm[i:i + cfg.batch_size]
batch_x = xp.array(train_x[local_perm])
batch_y = xp.array(train_y[local_perm])
if cfg.test:
for j in range(0, len(batch_x)):
ix = iproc.to_image(batch_x[j], cfg.ch)
iy = iproc.to_image(batch_y[j], cfg.ch)
ix.save(os.path.join(cfg.test_dir, "test_%d_x.png" % j))
iy.save(os.path.join(cfg.test_dir, "test_%d_y.png" % j))
six.print_(" * press any key...", end=" ")
six.moves.input()
optimizer.zero_grads()
pred = model(batch_x)
// loss = F.mean_squared_error(pred, batch_y)
loss = clipped_weighted_huber_loss(pred, batch_y, cfg.weight)
loss.backward()
optimizer.update()
sum_loss += loss.data * len(batch_x)
After Change
def train_inner_epoch(model, optimizer, cfg, train_x, train_y):
sum_loss = 0
scale = 1. / 255.
xp = utils.get_model_module(model)
perm = np.random.permutation(len(train_x))
for i in range(0, len(train_x), cfg.batch_size):
local_perm = perm[i:i + cfg.batch_size]
batch_x = xp.array(train_x[local_perm], dtype=np.float32) * scale
batch_y = xp.array(train_y[local_perm], dtype=np.float32) * scale
if cfg.test:
for j in range(0, len(batch_x)):
ix = iproc.to_image(batch_x[j], cfg.ch)
iy = iproc.to_image(batch_y[j], cfg.ch)
ix.save(os.path.join(cfg.test_dir, "test_%d_x.png" % j))
iy.save(os.path.join(cfg.test_dir, "test_%d_y.png" % j))
six.print_(" * press any key...", end=" ")
six.moves.input()
optimizer.zero_grads()
pred = model(batch_x)
// loss = F.mean_squared_error(pred, batch_y)
loss = clipped_weighted_huber_loss(pred, batch_y, cfg.weight)
loss.backward()
optimizer.update()
sum_loss += loss.data * len(batch_x)
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 5
Instances
Project Name: tsurumeso/waifu2x-chainer
Commit Name: 97aeda2a947c44cdef91d9276c2c38c02f37cda1
Time: 2017-02-08
Author: nstm101339@gmail.com
File Name: train.py
Class Name:
Method Name: train_inner_epoch
Project Name: tsurumeso/waifu2x-chainer
Commit Name: 97aeda2a947c44cdef91d9276c2c38c02f37cda1
Time: 2017-02-08
Author: nstm101339@gmail.com
File Name: train.py
Class Name:
Method Name: train_inner_epoch
Project Name: tsurumeso/waifu2x-chainer
Commit Name: 97aeda2a947c44cdef91d9276c2c38c02f37cda1
Time: 2017-02-08
Author: nstm101339@gmail.com
File Name: train.py
Class Name:
Method Name: valid_inner_epoch