记录使用tensorflow实现大卷积核卷积的代码
来源:互联网 发布:unity3d建立一个ui界面 编辑:程序博客网 时间:2024/06/09 16:17
#-*- coding:utf-8 -*-import tensorflow as tfimport cv2import numpy as npimport matplotlib.pyplot as plt## read img #####tm_path = '/home/wdh/pytorch-CycleGAN-and-pix2pix1_run/datasets/maps_0/testA/1_A.jpg'ref_path = '/home/wdh/pytorch-CycleGAN-and-pix2pix1_run/datasets/maps_0/testB/1_B.jpg'img_ref_bgr = cv2.imread(ref_path)img_tm_bgr = cv2.imread(tm_path)img_ref_gray = (cv2.cvtColor(img_ref_bgr,cv2.COLOR_BGR2GRAY))/255.0img_src_gray = (cv2.cvtColor(img_tm_bgr,cv2.COLOR_BGR2GRAY))/255.0[h_ref,w_ref] = img_ref_gray.shape[h_tm,w_tm] = img_src_gray.shapeh_tm = int(h_tm/3)w_tm = int(w_tm/3)img_tm_gray = np.zeros([h_ref,w_ref])img_tm_gray[0:h_tm,0:w_tm] = np.copy(img_src_gray[h_tm:h_tm+h_tm,w_tm:w_tm+w_tm])###################################build compute graph#################Var_tm = tf.Variable(img_tm_gray,dtype=tf.float32)Var_ref = tf.Variable(img_ref_gray,dtype=tf.float32)F_tm = tf.fft2d(tf.complex(Var_tm,tf.zeros(Var_tm.shape)))F_ref = tf.fft2d(tf.complex(Var_ref,tf.zeros(Var_ref.shape)))F_m = tf.multiply(F_ref,F_tm)# F_m = F_ref * F_tmres = tf.real(tf.ifft2d(F_m))optmizer = tf.train.AdamOptimizer(0.05)loss = -tf.reduce_max(res)train = optmizer.minimize(loss)init = tf.global_variables_initializer()###################################################run gragh ##############with tf.Session() as sess: sess.run(init) for _ in range(500): sess.run(train) d = sess.run(Var_tm) c = sess.run(Var_ref) b = sess.run(loss) a = np.array(sess.run(res)) print(b) print(np.max(a),np.min(a)) plt.figure() plt.subplot(221),plt.imshow(d,cmap='gray') plt.subplot(222), plt.imshow(c, cmap='gray') plt.subplot(223), plt.imshow(img_src_gray, cmap='gray') plt.subplot(224), plt.imshow(a, cmap='gray') plt.show()
阅读全文
0 0
- 记录使用tensorflow实现大卷积核卷积的代码
- 【Tensorflow】实现简单的卷积神经网络CNN实际代码
- TensorFlow实现卷积神经网络
- Tensorflow实现卷积神经网络
- Tensorflow实现卷积神经网络
- Tensorflow实现卷积神经网络
- TensorFlow实现卷积神经网络
- Tensorflow实现卷积神经网络
- Tensorflow实现卷积神经网络
- TensorFlow实现卷积神经网络
- tensorflow 卷积神经网络实现
- Tensorflow实现卷积神经网络
- tensorflow 经典卷积神经网络的实现
- Tensorflow实现进阶的卷积网络
- tensorflow:3)实现简单的卷积网络
- tensorflow实现简单的卷积神经网络
- 卷积神经网络LeNet5,基于TensorFlow的实现
- TensorFlow实现简单的卷积网络
- PE文件框架结构图
- LintCode之6 合并排序数组
- DevExpress 下TreeList下的节点复选框的显隐设置
- 【Java】【网络协议】Http,TCP/IP,Socket,XMMP
- Python 常用函数介绍及备忘
- 记录使用tensorflow实现大卷积核卷积的代码
- 十大基于Docker的开发工具
- 匿名类型、扩展方法
- HEIF:Technical information
- mongodb系列-访问控制
- Javascript的异步编程(下)及es6之generator
- 自定义类加载器的问题
- 自定义模型
- wxdl文件详解