记录使用tensorflow实现大卷积核卷积的代码
2017-11-24 16:11
453 查看
#-*- coding:utf-8 -*- import tensorflow as tf import cv2 import numpy as np import 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.0 img_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.shape h_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_tm res = 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()
相关文章推荐
- Tensorflow卷积实现原理+手写python代码实现卷积
- java使用动态代理来实现AOP(日志记录)的实例代码
- caffe实现3D卷积代码 C3D 安装遇到的问题记录
- 两行代码搞定iOS自定义HUD风格动画弹窗(支持选择记录) - SKChoosePopView的使用和实现思路
- mansory使用记录&&NSLayoutConstraint-代码实现自动布局
- java使用动态代理来实现AOP(日志记录)的实例代码
- 春节期间小明使用微信收到很多个红包,非常开心。在查看领取红包记录时发现,某个红包金额出现的次数超过了红包总数的一半。请帮小明找到该红包金额。写出具体算法思路和代码实现,要求算法尽可能高效。
- 春节期间小明使用微信收到很多个红包,非常开心。在查看领取红包记录时发现,某个红包金额出现的次数超过了红包总数的一半。请帮小明找到该红包金额。写出具体算法思路和代码实现,要求算法尽可能高效。
- TensorFlow使用C++加载使用训练好的模型,.cc文件代码实现的相关类及方法总结
- 在asp中通过getrows实现数据库记录分页的一段代码
- asp中通过getrows实现数据库记录分页的一段代码
- 用javascript实现记录来宾姓名的代码
- 使用vb.net代码实现图像水印技术
- 使用自定义标签实现JSP页面和代码的分离
- ESC之ESC.wsf可以实现javascript的代码压缩附使用方法第1/5页
- ESC之ESC.wsf可以实现javascript的代码压缩附使用方法第1/5页
- 两则实现相同功能的代码比较(使用临时表与不用临时表比较)
- 市面上所有号称"虚拟机","防火墙"的实时监控杀毒软件无一不是使用的IFSHOOK技术.但是同时也有一些朋友不断写MAIL给我打听如何实现读写的监控.下面给出用VTOOLSD写的代码.也就是所有实时杀毒软件的奥秘.同时,很多拦截文件操作的软件,例如对目录加
- 有关打印、收藏等的JS代码(打印等主要使用了一个IE组件来实现)
- 使用C#代码实现增加用户帐号