zoukankan      html  css  js  c++  java
  • CNN设计一些问题

    前提条件:在成功安装tensorflow基础上

    问题1:如何测试自己安装的tensorflow是否正确工作?

    1 # -*- coding:utf-8 -*-
    2 
    3 # 这个文件主要是用来测试自己安装的tensorflow-gpu是否正确工作
    4 
    5 import tensorflow as tf
    6 
    7 hello = tf.constant('hello Tensorflow')
    8 with tf.Session() as sess:
    9     print(sess.run(hello))

    问题2:如何计算CNN中的max_pool的输出尺寸?

    # -*- coding:utf-8 -*-
    import tensorflow as tf
    
    
    # 可以在这里修改尺寸
    input = tf.Variable(tf.random_normal([72,11,11,1]))
    
    # max_pool窗口的尺寸和stride的尺寸
    pool = tf.nn.max_pool(input, ksize=[1, 4, 4, 1], strides=[1, 4, 4, 1], padding="SAME")
    
    
    with tf.Session() as sess:
        tf.initialize_all_variables().run()
        sess.run(pool)
        print(pool.shape)

    问题3:填充方式VALID和SAME的区别?

     1 # -*- coding:utf-8 -*-
     2 
     3 import math
     4 
     5 # 这个文件主要用来对比一下VALID和SAME的区别
     6 
     7 # calculate size of output
     8 def calculate_output_size(padding, input_size, filter_size, stride):
     9     #
    10     if padding == "VALID": # 不填充
    11         return [math.ceil((input_size[0]-filter_size[0]+1)/stride[0]), math.ceil((input_size[1]-filter_size[1]+1)/stride[1])]
    12     elif padding == "SAME": # 填充
    13         return [math.ceil((input_size[0]/stride[0])), math.ceil((input_size[1]/stride[1]))]
    14     else:
    15         return None
    16 
    17 if __name__ == "__main__":
    18     print(calculate_output_size('SAME', input_size=[128,128], filter_size=[5, 5], stride=[1,1]))
  • 相关阅读:
    re正则表达式公式讲解3
    re正则表达式2
    re正则表达式公式讲解1
    洛谷 P2962 [USACO09NOV]灯Lights
    9.26模拟赛
    BZOJ 1567: [JSOI2008]Blue Mary的战役地图

    洛谷 P2919 [USACO08NOV]守护农场Guarding the Farm
    洛谷P3252 [JLOI2012]树
    P3183 [HAOI2016]食物链
  • 原文地址:https://www.cnblogs.com/wylwyl/p/10244969.html
Copyright © 2011-2022 走看看