Tensorflow1.0 实现Sptial Transformer Networks遇到的问题

大米饭盖不住四喜丸子 2017-02-28 11:01:06
最近找到githurb上stn的项目,是基于Tensorflow0.7的
本人使用环境 tensorflow1.0 python3.5
以下为报错
File "C:\Users\hasee\STN_tf_test01.py", line 38, in <module>
h_trans=transformer(x,h_fc1,out_size)
File "C:\Users\hasee\STN_tf_01.py", line 145, in transformer
output = _transform(theta, U, out_size)
File "C:\Users\hasee\STN_tf_01.py", line 122, in _transform
grid = _meshgrid(out_height, out_width)
File "C:\Users\hasee\STN_tf_01.py", line 102, in _meshgrid
grid = tf.concat(0, [x_t_flat, y_t_flat, ones])
File "C:\Users\hasee\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\ops\array_ops.py", line 1047, in concat
dtype=dtypes.int32).get_shape(
File "C:\Users\hasee\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\framework\ops.py", line 651, in convert_to_tensor
as_ref=False)
File "C:\Users\hasee\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\framework\ops.py", line 716, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "C:\Users\hasee\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\framework\constant_op.py", line 176, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "C:\Users\hasee\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\framework\constant_op.py", line 165, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "C:\Users\hasee\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\framework\tensor_util.py", line 367, in make_tensor_proto
_AssertCompatible(values, dtype)
File "C:\Users\hasee\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\framework\tensor_util.py", line 302, in _AssertCompatible
(dtype.name, repr(mismatch), type(mismatch).__name__))

builtins.TypeError: Expected int32, got list containing Tensors of type '_Message' instead.



报错部分代码如下:

def _meshgrid(height, width):
print('begin--meshgrid')
with tf.variable_scope('_meshgrid'):
# This should be equivalent to:
# x_t, y_t = np.meshgrid(np.linspace(-1, 1, width),
# np.linspace(-1, 1, height))
# ones = np.ones(np.prod(x_t.shape))
# grid = np.vstack([x_t.flatten(), y_t.flatten(), ones])

x_t = tf.matmul(tf.ones(shape=tf.stack([height, 1])),
tf.transpose(tf.expand_dims(tf.linspace(-1.0, 1.0, width), 1), [1, 0]))
print('meshgrid_x_t_ok')
y_t = tf.matmul(tf.expand_dims(tf.linspace(-1.0, 1.0, height), 1),
tf.ones(shape=tf.stack([1, width])))
print('meshgrid_y_t_ok')
x_t_flat = tf.reshape(x_t, (1, -1))
y_t_flat = tf.reshape(y_t, (1, -1))
print('meshgrid_flat_t_ok')
ones = tf.ones_like(x_t_flat)
print('meshgrid_ones_ok')
print(x_t_flat)
print(y_t_flat)
print(ones)
grid = tf.concat(0, [x_t_flat, y_t_flat, ones])#报错语句
print ('over_meshgrid')
return grid


以及上级代码如下:
im=ndimage.imread('C:\\Users\\hasee\\Desktop\\cat.jpg')
im=im/255.
#im=tf.reshape(im, [1,1200,1600,3])

im=im.reshape(1,1200,1600,3)

im=im.astype('float32')
print('img-over')
out_size=(600,800)
batch=np.append(im,im,axis=0)
batch=np.append(batch,im,axis=0)
num_batch=3

x=tf.placeholder(tf.float32,[None,1200,1600,3])
x=tf.cast(batch,'float32')
print('begin---')
with tf.variable_scope('spatial_transformer_0'):
n_fc=6
w_fc1=tf.Variable(tf.Variable(tf.zeros([1200*1600*3,n_fc]),name='W_fc1'))
initial=np.array([[0.5,0,0],[0,0.5,0]])
initial=initial.astype('float32')
initial=initial.flatten()


b_fc1=tf.Variable(initial_value=initial,name='b_fc1')


h_fc1=tf.matmul(tf.zeros([num_batch,1200*1600*3]),w_fc1)+b_fc1

print(x,h_fc1,out_size)

h_trans=transformer(x,h_fc1,out_size)


sess=tf.Session()
sess.run(tf.global_variables_initializer())
y=sess.run(h_trans,feed_dict={x:batch})
plt.imshow(y[0])
plt.show()


...全文
3381 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
无比滴 2017-03-19
  • 打赏
  • 举报
回复
通过楼主的博客也找到解决方法啦,tf.contact()里面的参数换下位置就OK啦。
grid = tf.concat(0, [x_t_flat, y_t_flat, ones])#报错语句
grid = tf.concat( [x_t_flat, y_t_flat, ones],0) #楼主改后的代码
无比滴 2017-03-19
  • 打赏
  • 举报
回复
遇到同样问题了,期待大神看到帖子回来分享解决方法。
on2way 2017-03-14
  • 打赏
  • 举报
回复
怎么解决的 原因呢 这个网友。。
heavenpeien 2017-03-07
  • 打赏
  • 举报
回复
so why ?
qq_26240809 2017-03-01
  • 打赏
  • 举报
回复
我也碰到了这个问题,能说下是怎么解决的吗?谢谢!
  • 打赏
  • 举报
回复
已解决所有问题
  • 打赏
  • 举报
回复
在tensorflow0.12下运行正常,可疑点貌似是tf.expand_dims api修改后,带来的问题
内容概要:本文聚焦于高维多阶段随机规划问题,深入研究了正则化分解方法与马尔可夫过程在刻画不确定性动态演化中的应用,并提供了完整的Python代码实现。通过引入正则化技术有效降低了高维随机优化问题的计算复杂度,结合马尔可夫链建模多阶段决策过程中的不确定性传播机制,提升了模型在复杂动态环境下的求解效率与鲁棒性。研究涵盖了问题建模、算法设计、数值求解及结果分析全过程,具有较强的理论深度与工程实践价值; 适合人群:具备一定运筹学、优化理论基础及Python编程能力,从事智能决策、人工智能、能源系统优化、金融工程等相关领域的科研人员、高校研究生以及工业界研发工程师; 使用场景及目标:①应用于电力系统调度、供应链管理、金融资产配置等存在多阶段不确定性的复杂决策场景;②掌握高维随机规划的建模思路与高效求解技术,深入理解正则化方法与马尔可夫过程在实际优化算法中的融合机制与实现路径; 阅读建议:建议结合提供的Python代码进行动手实践,重点关注算法实现细节、参数敏感性分析与收敛性验证,鼓励在不同应用场景中迁移和改进该方法,进一步探索其在分布鲁棒优化、动态规划等前沿方向的扩展潜力。
内容概要:本文系统研究了离散时间线性系统中基于共识的分布式滤波器的稳定性与最优性问题,深入探讨了KF(卡尔曼滤波)、DKF(分布式卡尔曼滤波)、SMDKF(基于平方根的最大熵分布式卡尔曼滤波)、CI(协方差交叉)、ICF(信息共识滤波)和HCMCI(基于高阶交叉协方差的信息融合)等多种滤波算法的理论基础、数学推导与实现机制。通过Matlab平台构建多传感器网络仿真环境,实现了各类算法在不同噪声统计特性和通信拓扑结构下的状态估计仿真,重点分析了各算法在估计精度、收敛速度、鲁棒性及一致性方面的性能差异,并对融合策略中的协方差传播、信息权重分配与共识迭代过程进行了细致对比,旨在为复杂环境下多智能体系统的分布式状态估计提供可复现的技术方案与理论支撑。; 适合人群:具备控制理论、信号处理、线性系统理论及Matlab编程基础的研究生、科研人员,以及从事多传感器融合、分布式估计算法开发、无人系统导航与智能电网监控等领域的工程技术人员。; 使用场景及目标:① 掌握主流分布式滤波算法的核心思想与数学建模方法;② 在多节点传感网络中实现高效可靠的状态估计;③ 对比分析不同共识融合策略在非理想通信条件下的性能表现;④ 支持学术论文复现、算法改进与工程化验证,服务于科研创新与系统优化设计。; 阅读建议:建议结合Matlab代码逐模块解析算法实现流程,重点关注状态预测、局部更新、信息融合与一致性达成的关键步骤;可通过调整系统噪声、观测噪声、网络连接拓扑等参数开展扩展性仿真实验,深入理解算法的稳定边界与最优性条件,进一步探索其在实际应用场景中的适应性与改进空间。

4,511

社区成员

发帖
与我相关
我的任务
社区描述
图形图像/机器视觉
社区管理员
  • 机器视觉
  • 迪菲赫尔曼
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧