cnn神经网络卷积层可视化

2 篇文章 0 订阅
cnn神经网络卷积层可视化

1.修改model.py文件的定义网络输出函数

def inference(images,batch_size, n_classes):
###你的卷积层、全连接层、softmax层定义
    return softmax_linear,conv1,conv2

2.修改测试函数

logit ,conv1,conv2= model.inference(image,BATCH_SIZE,n_class)
with tf.Session() as sess:
    ckpt = tf.train.get_checkpoint_state(logits_train_dir)#读取训练好的参数
    if ckpt and ckpt.model_checkpoint_path:
        global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
        saver.restore(sess,ckpt.model_checkpoint_path)
        print('loading sucess,global-step is %s' % global_step)
    else:
        print('No checkpoint file found')
    conv1 = sess.run(conv1,feed_dict={x: image_array})#计算第一层卷积输出
    conv2 = sess.run(conv2,feed_dict={x: image_array})#计算第二层卷积输出

3.输出卷积层结果

    fig, axes = plt.subplots(4, 4, figsize=(6, 6),
                         subplot_kw={'xticks': [], 'yticks': []})

    fig.subplots_adjust(left=0.02, bottom=0.06, right=0.95, top=0.94, wspace=0.05)
    for i,ax in zip(range(16), axes.flat):
        ax.imshow(conv2[0,:,:,i])
    plt.show()

这里写图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值