tesorflow 填充‘same’与‘valid’
生活随笔
收集整理的這篇文章主要介紹了
tesorflow 填充‘same’与‘valid’
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
源碼:
#coding=utf-8import tensorflow as tf# case 2 input = tf.Variable(tf.random_normal([1, 256, 256, 3]))op1 = tf.layers.conv2d(inputs=input, filters=164, kernel_size=(7, 7), strides=(2, 2), padding="same", activation=tf.nn.relu)op2 = tf.layers.conv2d(inputs=input, filters=64, kernel_size=(7, 7), strides=(2, 2), padding="same", activation=tf.nn.relu)op3 = tf.layers.conv2d(inputs=input, filters=64, kernel_size=(7, 7), strides=(2, 2), padding="valid", activation=tf.nn.relu)op0 = tf.concat([op1, op2], 3)init = tf.initialize_all_variables() with tf.Session() as sess: sess.run(init) print("case 2") print('op0:', sess.run(op0).shape) print('op2:', sess.run(op2).shape) print('op3', sess.run(op3).shape) 輸出:?
?
?
卷積核大小 :filter*filter,步長:stride,填充:padding,圖像大小:h*w
卷積后圖像大小 高 height =(h - filter +2*padding)/stride +1?
?
‘same’填充2,向上取整
對op2 ? height = (256-7+2*2)/2+1 = 127.5 向上取整:128
?? 卷積后維度(1,128,128,64)
?
‘valid’填充0,向下取整
對op2 ? height = (256-7)/2+1 = 125.5 向上取整:125
?? 卷積后維度(1,125,125,64)
?
?
?
?
?
總結
以上是生活随笔為你收集整理的tesorflow 填充‘same’与‘valid’的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tf.clip_by_value()
- 下一篇: tf.layers.dense