GAN (Generative Adversarial Network,GAN)生成式对抗网络

在这里插入图片描述
在这里插入图片描述处理可忽略的报错

import warnings
warnings.filterwarnings("ignore")

克隆仓库

git clone https://gitee.com/mindspore/models.git
cp -r ~/CANN/models/research/cv/wgan ./wgan/
cp -r ~/CANN/models/research/cv/gan ./gan/

最后没仔细看,要求的是mnist即可
那我们就搞一个mnist的脚本
注意scipy.misc已经没有imsave了

def save_img(img, fname):
    pil_img = deprocess_image(np.copy(img))
    scipy.misc.imsave(fname, pil_img)

改成

def save_img(img, fname):
    pil_img = deprocess_image(np.copy(img))
    imageio.imwrite(fname, pil_img)

在这里插入图片描述
本地训练较慢,那我们只训练3轮
在云脑上,我们同步训练一个:

pip install tensorflow-gpu==1.13.1
测试GPU
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
--------
import tensorflow as tf
tf.debugging.set_log_device_placement(True)
--------
# Place tensors on the CPU
with tf.device('/GPU:0'):
  a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
  b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
--------
c = tf.matmul(a, b)
print(c)
--------
import tensorflow as tf
print (tf.__version__)
if tf.test.gpu_device_name():
    print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
    print("Please install GPU version of TF")

wgan恢复为gan
wgan定义的:

            # gradient penalty

            gp = gradient_penalty(D, xr, xf.detach())


            # aggregate all

            loss_D = lossr + lossf + 0.2 * gp

改为

# aggregate all
            loss_D = lossr + lossf

在这里插入图片描述
如果想不输出解压过程

unzip xx.zip > /dev/null 2>&1

在这里插入图片描述
在这里插入图片描述
pytorch也可以实现类似的功能。

读取tfevents
读取的步骤:①先转到events.out.tfevents所在的文件目录下

                  命令:cd dir(所在文件夹目录)

                  ②tensorboard --logdir dir(文件所在文件夹)

                  ③firefox浏览器打开第二部生成的网址,例如http://ubuntu122:6006/ 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

irrationality

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值