img=tmp[i][j:j+8] img=np.transpose(img.reshape(64*8,64),(1,0)) img_array2.append(img) img_array2=np.array(img_array2).reshape(int(batchsize/8*64),8*64) img_array.append(np.transpose(img_array2,(1,0))) img_array = np.array(img_array) print("\nsave fig...") save_img(img_array,save_path+"/{}.png".format(str(epoch).zfill(3))) print("fake_gen_loss:{}(all/{}) fake_dis_loss:{}(all/{}), real_dis_loss:{}(all/{})".format(loss_fake_gen/float(n_fake_gen),n_fake_gen,loss_fake_dis/float(n_fake_dis),n_fake_dis,loss_real_dis/float(n_real_dis),n_real_dis)) #losses are approximated values print('save model ...') prefix = save_path+"/model/"+str(epoch).zfill(3) if os.path.exists(prefix)==False: os.mkdir(prefix) serializers.save_npz(prefix + '/Geights', Gen.to_cpu()) serializers.save_npz(prefix + '/Goptimizer', optG) serializers.save_npz(prefix + '/Dweights', Dis.to_cpu()) serializers.save_npz(prefix + '/Doptimizer', optD) Gen.to_gpu() Dis.to_gpu() real_belief_mean = 0.0 fake_belief_mean = 0.0 for j,(data,charaid,poseid) in enumerate(real.gen_test(1)): x = Variable(xp.array(data)) label = Variable(xp.ones((1,1),dtype=xp.int32)) y, loss = Dis(x,label,train=False) real_belief_mean += xp.sum(y.data) sys.stdout.write("\rtest real...{}/{}".format(j,testsize)) sys.stdout.flush() print(" test real belief mean:{}({}/{})".format(real_belief_mean/testsize,real_belief_mean,testsize))
8 * 64) img_array.append(np.transpose(img_array2, (1, 0))) img_array = np.array(img_array) print("\nsave fig...") save_img(img_array, f"{save_path}/{str(epoch).zfill(3)}.png") print(f"fake_gen_loss:{loss_fake_gen/n_fake_gen}(all/{n_fake_gen}), \ fake_dis_loss:{loss_fake_dis/n_fake_dis}(all/{n_fake_dis}), \ real_dis_loss:{loss_real_dis/n_real_dis}(all/{n_real_dis})" ) #losses are approximated values print('save model ...') prefix = f"{save_path}/model/str(epoch).zfill(3)" if os.path.exists(prefix) == False: os.mkdir(prefix) serializers.save_npz(f"{prefix}/Geights", Gen.to_cpu()) serializers.save_npz(f"{prefix}/Goptimizer", optG) serializers.save_npz(f"{prefix}/Dweights", Dis.to_cpu()) serializers.save_npz(f"{prefix}/Doptimizer", optD) Gen.to_gpu() Dis.to_gpu() real_belief_mean = 0.0 fake_belief_mean = 0.0 for j, (data, charaid, poseid) in enumerate(real.gen_test(batchsize)): x = Variable(xp.array(data)) B = x.shape[0] label = Variable(xp.ones((B, 1), dtype=xp.int32)) with chainer.using_config('train', False), chainer.no_backprop_mode(): y, loss = Dis(x, label) real_belief_mean += xp.sum(y.data) sys.stdout.write(f"\rtest real...{j}/{testsize/batchsize}") sys.stdout.flush()