tensorflow实现反卷积
生活随笔
收集整理的這篇文章主要介紹了
tensorflow实现反卷积
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
先看ogrid用法
from numpy import ogrid,repeat,newaxis
from skimage import io
import numpy as np
size=3
x,y=ogrid[:size,:size]#第一部分產生多行一列 第二部分產生一行多列
print(x)
print(y)
打印結果:
newaxis用法:
""" newaxis用法 增加維度 """ x=np.random.randint(1,8,size=(2,3,4)) print(x.shape) y=x[:,np.newaxis,:,:] print(y.shape) y=x[:,:,np.newaxis,:] print(y.shape)打印結果:
repeat用法:
""" repeat用法 拓展 """ a=np.array([1,2,3]) b=repeat(a,2) print(b) x = np.array([[1,2],[3,4]]) y=np.repeat(x, 2) print(y) y=np.repeat(x, 3, axis=1) print(y) y=np.repeat(x, [1, 2], axis=0) print(y) """ 生成3×3×3黑色圖像 """ size=3 x,y=ogrid[:size,:size]#第一部分產生多行一列 第二部分產生一行多列 z=x+y z=z[:,:,newaxis]#增加第三維 img=repeat(z,3,2)#在第三維上復制 io.imshow(img,interpolation='none') io.show()從一個5×5×3上采樣生成9×9×3? 圖像
""" 生成5×5×3黑色圖像 """ size=5 x,y=ogrid[:size,:size]#第一部分產生多行一列 第二部分產生一行多列 z=x+y z=z[:,:,newaxis]#增加第三維 img=repeat(z,3,2)/12#在第三維上復制 io.imshow(img,interpolation='none') io.show() """ upsampling 生成9×9的圖像 """ import tensorflow as tf img=tf.cast(img,dtype=tf.float32) img=tf.expand_dims(img,0)#增加維度 #隨機生成卷積核 kernel=tf.random_uniform(shape=[5,5,3,3],dtype=tf.float32) # kernel=tf.random_normal(shape=[5,5,3,3],dtype=tf.float32) #反卷積 res=tf.nn.conv2d_transpose(img,kernel,output_shape=[1,9,9,3],strides=[1,1,1,1],padding='VALID') with tf.Session() as sess:img=sess.run(res) io.imshow(img[0,:,:,:]/np.argmax(img),interpolation='none') io.show()打印結果:
?
?
?
總結
以上是生活随笔為你收集整理的tensorflow实现反卷积的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 剑指 Offer 03. 数组中重复的数
- 下一篇: Android之Fragment(二)