Skip to content

Commit

Permalink
Change tensorflow to tensorboardX
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjunh committed Jan 30, 2019
1 parent d7f7c52 commit cf52ed0
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions train.py
@@ -1,6 +1,6 @@
import time
import sys
import tensorflow as tf
from tensorboardX import SummaryWriter
sys.path.append('options')
from train_options import TrainOptions
sys.path.append('data')
Expand All @@ -14,13 +14,7 @@
data_loader = CreateDataLoader(opt)
model = CreateModel(opt)

sess = tf.Session()
loss_g = tf.placeholder(tf.float32)
loss_d = tf.placeholder(tf.float32)
me1 = tf.summary.scalar('loss_g', loss_g)
me2 = tf.summary.scalar('loss_d', loss_d)
merged = tf.summary.merge([me1, me2])
writer = tf.summary.FileWriter("logs", sess.graph)
writer = SummaryWriter('logs')

err = err(model.save_dir)
for epoch in range(opt.count_epoch + 1, opt.epochs + 1):
Expand All @@ -37,8 +31,8 @@
err.add(model.Loss_G.data.item(), model.Loss_D.data.item())

LOSSG, LOSSD = err.print_errors(epoch)
summary = sess.run(merged, feed_dict={loss_g: LOSSG, loss_d: LOSSD})
writer.add_summary(summary, epoch)
writer.add_scalar('loss_g', LOSSG, epoch)
writer.add_scalar('loss_d', LOSSD, epoch)
print('End of epoch {0} \t Time Taken: {1} sec\n'.format(epoch, time.time()-epoch_start_time))
model.save_result(epoch)
if epoch % opt.save_epoch_freq == 0:
Expand Down

3 comments on commit cf52ed0

@shineonme56
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I got this error,

/home/pirl/anaconda3/lib/python3.7/site-packages/torchvision/transforms/transforms.py:208: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead.
warnings.warn("The use of the transforms.Scale transform is deprecated, " +
model Multi_DRGAN was created
Traceback (most recent call last):
File "/home/pirl/FaceRecognition/pytorch/train.py", line 29, in
model.optimize_D_parameters()
File "model/DRGAN.py", line 433, in optimize_D_parameters
self.backward_D()
File "model/DRGAN.py", line 419, in backward_D
self.Loss_D_real_pose.append(self.criterion(self.real_pose[m], self.pose[m]))
File "/home/pirl/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/home/pirl/anaconda3/lib/python3.7/site-packages/torch/nn/modules/loss.py", line 942, in forward
ignore_index=self.ignore_index, reduction=self.reduction)
File "/home/pirl/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py", line 2056, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
File "/home/pirl/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py", line 1871, in nll_loss
ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: Expected object of scalar type Long but got scalar type Byte for argument #2 'target'

pytorch version is 1.1.0
python version is 3.7

Could you tell me what is causing this error? thank you!!

@zhangjunh
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @JiWung-Han , this repo is using pytorch version 0.2, so it can't work with pytorch version 1.1.0.

@shineonme56
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change the version and try again, thanks a lot :) @zhangjunh

Hi @JiWung-Han , this repo is using pytorch version 0.2, so it can't work with pytorch version 1.1.0.

Please sign in to comment.