kanji_gan.py 文件源码

python
阅读 51 收藏 0 点赞 0 评论 0

项目:MachineLearning 作者: timomernick 项目源码 文件源码
def test():
    print("testing...")
    generator_model = "gen_epoch_39.pth"
    discriminator_model = "disc_epoch_39.pth"    
    generator.load_state_dict(torch.load(generator_model))
    discriminator.load_state_dict(torch.load(discriminator_model))

    dump_sheet = True
    if (dump_sheet):
        fake = generator(fixed_noise)
        out_file = "sheet.png"
        print("saving to: " + out_file)
        vutils.save_image(fake.data, out_file)

    make_video = True
    if (make_video):
        video_noise = Variable(torch.FloatTensor(1, nz, 1, 1)).cuda()
        video_noise_cpu = fixed_noise[0].data.cpu().numpy()#np.random.normal(loc=0.0, scale=1.0, size=[1, nz, 1, 1])
        video_noise.data.copy_(torch.from_numpy(video_noise_cpu))

        noise_vel_speed = 0.05
        video_noise_vel = np.random.uniform(low=-noise_vel_speed, high=noise_vel_speed, size=[1, nz, 1, 1])

        num_frames = 300
        for frame_idx in range(num_frames):
            print(frame_idx)

            video_frame = generator(video_noise).data.cpu().numpy()
            video_frame = video_frame.reshape([nc, image_size, image_size]).transpose()

            scipy.misc.imsave("frame_" + str(frame_idx).zfill(5) + ".png", video_frame.reshape([image_size, image_size]))

            video_noise_cpu = np.mod(video_noise_cpu + video_noise_vel, 1.0)
            video_noise.data.copy_(torch.from_numpy(video_noise_cpu))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号