日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tensorflow:双线性插值反卷积

發(fā)布時間:2024/7/23 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tensorflow:双线性插值反卷积 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
首先生成3×3×3的黑色圖片 """ 生成3×3×3黑色圖像 """ def produce_image():size = 3x, y = ogrid[:size, :size] # 第一部分產(chǎn)生多行一列 第二部分產(chǎn)生一行多列z = x + yz = z[:, :, newaxis] # 增加第三維# print(z)img = repeat(z, 3, 2)/12 # 在第三維上復(fù)制兩遍# print(img.shape)# print(img)io.imshow(img, interpolation='none')io.show()return img

打印結(jié)果:

雙線性插值反卷積代碼如下:

""" 生成3×3×3黑色圖像 """ def produce_image():size = 3x, y = ogrid[:size, :size] # 第一部分產(chǎn)生多行一列 第二部分產(chǎn)生一行多列z = x + yz = z[:, :, newaxis] # 增加第三維# print(z)img = repeat(z, 3, 2)/12 # 在第三維上復(fù)制兩遍# print(img.shape)# print(img)io.imshow(img, interpolation='none')io.show()return img""" 上采樣 雙線性插值生成卷積核 """ def upsampling_bilinear():#確定卷積核大小def get_kernel_size(factor):return 2*factor-factor%2# 創(chuàng)建相關(guān)矩陣def upsample_filt(size):factor=(size+1)//2if size%2==1:center=factor-1else:center=factor-0.5og=np.ogrid[:size,:size]# print(og)# print(og[0])# print(og[1])return (1-abs(og[0]-center)/factor)*(1-abs(og[1]-center)/factor)#進(jìn)行上采樣卷積核def bilinear_upsample_weights(factor,number_of_classes):filter_size=get_kernel_size(factor)weights=np.zeros((filter_size,filter_size,number_of_classes,number_of_classes),dtype=np.float32)upsample_kernel=upsample_filt(filter_size)# print(upsample_kernel)for i in range(number_of_classes):weights[:,:,i,i]=upsample_kernel# print(weights[:,:,i,i])# print(weights)# print(weights.shape)return weightsweights=bilinear_upsample_weights(3,3)return weights if __name__ == '__main__':import tensorflow as tf# upsampling()# upsampling_bilinear()image=produce_image()img = tf.cast(image, dtype=tf.float32)img = tf.expand_dims(img, 0) # 增加維度#產(chǎn)生卷積核kerenel=upsampling_bilinear()#反卷積處理res=tf.nn.conv2d_transpose(img,kerenel,output_shape=[1,9,9,3],strides=[1,3,3,1],padding='SAME')with tf.Session() as sess:img = sess.run(res)io.imshow(img[0, :, :, :] , interpolation='none')io.show()

打印結(jié)果:能較好恢復(fù)原圖像

總結(jié)

以上是生活随笔為你收集整理的tensorflow:双线性插值反卷积的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。