Tensorflow1.0 实现Sptial Transformer Networks遇到的问题
本人使用环境 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()相关推荐
熊数据集集2983张VOC+YOLO格式.zip
数据集格式:VOC格式+YOLO格式 压缩包内含:3个文件夹,分别存储图片、xml、txt文件 JPEGImages文件夹中jpg图片总计:2983 Annotations文件夹中xml文件总计:2983 labels文件夹中txt文件总计:2983 标签种类数:1 标签名称:["bear"] 每个标签的框数(注意yolo格式类别顺序不和这个对应,而以labels文件夹classes.txt为准): bear 框数 = 3021 总框数:3021 图片清晰度(分辨率:像素):清晰 图片是否增强:否 标签形状:矩形框,用于目标检测识别 重要说明:暂无 特别声明:本数据集不对训练的模型或者权重文件精度作任何保证,数据集只提供准确且合理标注
vue+springboot_基于Java语言的茶叶销售商城电商系统_176brjo7毕业设计源码数据库.zip
vue+springboot_基于Java语言的茶叶销售商城电商系统_176brjo7毕业设计源码数据库.zip
43一个强到且很实用的Linux网络管理工具.docx
43一个强到且很实用的Linux网络管理工具
【计量经济学】基于Oster无工具变量法的内生性处理:遗漏变量偏差敏感性分析与稳健因果效应界估算
内容概要:本文介绍了基于Oster(2019)提出的无工具变量法处理内生性问题的实现方法,核心是通过系数稳定性与拟合优度变化进行敏感性分析,量化遗漏变量偏差的影响,并估计在控制不可观测变量后的稳健因果效应β(beta tilde)。该方法利用两步回归(有无控制变量)之间的系数和R²变化,结合不可观测选择强度参数δ与最大潜在R²(Rmax),外推可能的因果效应边界,从而判断基准结果是否对遗漏变量稳健。文中提供了Stata(psacalc)、R(ooster包)和Python三种主流语言的具体实现代码与操作示例,强调结果依赖于参数设定,需进行敏感性扫描以增强说服力。 适合人群:经济学、管理学、社会学、公共卫生、教育等领域的实证研究者,尤其是正在撰写论文、面临审稿人关于内生性质疑的研究生与青年学者。 使用场景及目标:①在缺乏有效工具变量时,评估OLS回归结果对遗漏变量的敏感性;②生成稳健因果效应的点估计与置信区间,回应审稿人对内生性问题的质疑;③通过δ与Rmax的多值扫描,可视化展示结论稳健性。 阅读建议:此方法属于敏感性分析而非因果识别工具,应与IV、DID、固定效应等方法结合使用;使用者需确保两步回归样本一致,并替换示例中的变量名为实际数据变量,同时务必对关键参数开展敏感性测试,避免过度解读单一结果。
园区管理者如何通过数据分析精准培育创新主体?.docx
园区管理者如何通过数据分析精准培育创新主体?


