pclucas14 / pixel-cnn-pp

Pytorch Implementation of OpenAI's PixelCNN++
Other
344 stars 76 forks source link

Application of the trained model #19

Closed NeroArcher closed 4 years ago

NeroArcher commented 4 years ago

Currently I am trying to applicate some trained models to generate some images. For now, I only know that loading the model is something like the following: model.eval() data = torch.randn(1, 3, 24, 24) # dummy data output = model(data) prediction = torch.argmax(output) However, I am wondering that how I can get image result. Is it something like this part of your original code? `def sample(model): model.train(False) data = torch.zeros(sample_batch_size, obs[0], obs[1], obs[2]) data = data.cuda() for i in range(obs[1]): for j in range(obs[2]): data_v = Variable(data, volatile=True) out = model(data_v, sample=True) out_sample = sample_op(out) data[:, :, i, j] = out_sample.data[:, :, i, j] return data

sample_t = sample(model) sample_t = rescaling_inv(sample_t) utils.save_image(samplet,'images/{}{}.png'.format(model_name, epoch), nrow=5, padding=0) ` Or is it something else that I need to learn?

pclucas14 commented 4 years ago

Hi,

the code you linked does the sampling operation from the trained model. If you want to load and sample from a trained model, replace lines 111 until the end with

sample_t = sample(model)
sample_t = rescaling_inv(sample_t)
utils.save_image(sample_t, 'my_sample.png', nrow=5, padding=0)

and that should do it. Hopefully this answers your question

NeroArcher commented 4 years ago

Thank you very much! this does answer my question! By the way I noticed that you have from tensorboardX import SummaryWriter code in the main file. I am wondering how I can activate the tensorboard to visualise the model/training, should I add something using make_grid to the code to make it work?

pclucas14 commented 4 years ago

are you familiar with tensorboard ? just regular launching of tensorboard in the proper directory will do it

NeroArcher commented 4 years ago

are you familiar with tensorboard ? just regular launching of tensorboard in the proper directory will do it

Sorry I think I have found the problem, it is because I run the code on a remote server. I have got it working properly, thank you for your patience!