Beispiel #1
0
import sys
sys.path.insert(0, "/common/home/deeplearning/studdocs/gerasimov_d/LAB2/mxnet-cuda")

import mxnet as mx
from mxnet import gluon, autograd, ndarray
import numpy as np

import time
start_time = time.time()
from load_data2 import load_data
all_data, train_data, test_data = load_data()
elapsed_time = time.time() - start_time
print 'Time load data: ', elapsed_time

start_time = time.time()

model_ctx = mx.gpu(0)

shape_input = train_data[0][0].shape
size_inputs = train_data[0][0].size
num_outputs = train_data[0][1].size
num_hidden = train_data[0][1].size

from autoencoder_conf import prepare_autoencoder2
encoder, loss_encoder, decoder, loss_decoder = prepare_autoencoder2(num_hidden, num_outputs, model_ctx)
elapsed_time = time.time() - start_time
print 'Time of initializing data: ', elapsed_time

num_epochs = 15
learning_rate = .008
#dis=_netDw(1,3,64).cuda()
#refine=refine_().cuda()
optimizerae = optim.Adam(ae.parameters(), lr=lr_rate)
optimizervae = optim.Adam(vae.parameters(), lr=lr_rate)
#optimizerenco=optim.Adam(vae.enco.parameters(),lr=lr_rate)
#optimizerre=optim.Adam(refine.parameters(),lr=lr_rate)
#optimizerde=optim.RMSprop(dis.parameters(),lr=lr_rate)
datalist = ld.getlist('list_attr_train2.txt')
iternow1 = 0

state_dict = torch.load('refine_wgangpdeform/vae_iter_210000.pth.tar')
vae.load_state_dict(state_dict['VAE'])
#dis.load_state_dict(state_dict['dis'])
#refine.load_state_dict(state_dict['refine'])
#vae.eval()
imgpo, iternow1 = ld.load_data('/ssd/randomcrop_resize_64/',
                               'list_attr_train2.txt', datalist, iternow1, bs)
imgpo_re, mu, logvar, mu1, logvar1, mask0, mask1 = vae(imgpo)
#mask=vae.deco.fc4(vae.deco.fc3(vae.reparameterize(mu1,logvar1))).view(-1,3,16,16)
#mask=mask/int(torch.max(mask).data.cpu().numpy())
#saveim=imgpo.cpu().data
#tov.save_image(saveim,'img'+'.jpg')
#saveim=imgpo_re.cpu().data
#tov.save_image(saveim,'img_re'+'.jpg')
'''
eps0 = Vb(mu1.data.new(mu1.size()).normal_())
eps1 = Vb(mu.data.new(mu.size()).normal_())
recon,mask2 = vae.deco(eps0,eps1)
saveim=mask0.cpu().data
tov.save_image(saveim,'mask0'+'.jpg')
saveim=mask1.cpu().data
tov.save_image(saveim,'mask1'+'.jpg')