【发布时间】:2019-08-01 14:54:27
【问题描述】:
Tensorflow 中出现数据类型不匹配的错误。
我尝试过:
prediction = tf.convert_to_tensor(prediction)
y = tf.convert_to_tensor(y)
在传递给损失函数之前
def train():
print("Training")
# tf Graph input
x = tf.placeholder(dtype=tf.float32, shape=[None, config.input_window_size - 1, config.input_size], name="input_sequence")
y = tf.placeholder(dtype=tf.float32, shape=[None, config.output_window_size, config.input_size], name="raw_labels")
dec_in = tf.placeholder(dtype=tf.float32, shape=[None, config.output_window_size, config.input_size], name="decoder_input")
labels = tf.transpose(y, [1, 0, 2])
labels = tf.reshape(labels, [-1, config.input_size])
labels = tf.split(labels, config.output_window_size, axis=0, name='labels')
tf.set_random_seed(112858)
# Define model
prediction = models.seq2seq(x, dec_in, config, True)
sess = tf.Session()
loss = eval('loss_functions.lie_loss(prediction, labels, config)')
# Add a summary for the loss
train_loss = tf.summary.scalar('train loss', loss)
valid_loss = tf.summary.scalar('valid loss', loss)
损失函数
def lie_loss(prediction, y, config):
# Compute the joint discrepancy following forward kinematics of lie parameters
prediction = tf.concat(prediction, axis=0)
y = tf.concat(y, axis=0)
joint_pred = forward_kinematics(prediction, config)
joint_label = forward_kinematics(y, config)
loss = tf.reduce_mean(tf.square(tf.subtract(joint_pred, joint_label)))
return loss
我得到错误 TypeError:无法将类型对象转换为张量。内容:[无,-1, 3]。考虑将元素转换为支持的类型。
在将预测和 y 更改为张量时,我在 Forward_kinematics 中收到以下错误:
joint_pred = forward_kinematics(prediction, config)
Prediction/src/loss_functions.py", line 101, in forward_kinematics
for i in range(omega[0].shape[0]):
TypeError: __index__ returned non-int (type NoneType)
forward_kinematics 的函数如下:
def forward_kinematics(lie_parameters, config):
print(lie_parameters)
nframes = lie_parameters.get_shape().as_list()[0]
print("nframs")
print(nframes)
# nframes = lie_parameters.shape[0]
lie_parameters = tf.reshape(lie_parameters, [nframes, -1, 3])
R = []
idx = config.idx
chain_idx = config.chain_idx
# config bone params are retrieved from read_data.py
bone_params = config.bone_params
for h in range(nframes):
omega = []
A = []
chain = []
for i in range(len(idx) - 1):
chain.append(tf.concat([lie_parameters[h, idx[i]:idx[i + 1]], tf.zeros([1, 3])], axis=0))
omega.append(tf.concat(chain, axis=0))
##### I have to check this omega
print("Omega")
print(type(omega))
print(omega)
print(omega[0])
print(omega[0].shape)
print(omega[0].shape[0])
for i in range(omega[0].shape[0]):
A.append([rotmat(omega[0][i])])
R.append(tf.concat(A, axis=0))
R = tf.stack(R)
joints = []
for h in range(nframes):
jointlist = []
for i in range(len(chain_idx)):
for j in range(chain_idx[i].shape[0]):
if j == 0:
if i < 3:
jointlist.append(tf.zeros([3, 1]))
else:
jointlist.append(joint_xyz[14])
else:
k = j - 1
A = R[h, chain_idx[i][k]]
while k > 0:
k = k - 1
A = tf.matmul(R[h, chain_idx[i][k]], A)
jointlist.append(
tf.matmul(A, tf.reshape(bone_params[chain_idx[i][j]], [3, 1])) + joint_xyz[chain_idx[i][j - 1]])
joint_xyz = tf.stack(jointlist)
joints.append(tf.squeeze(joint_xyz))
joints = tf.stack(joints)
return joints
【问题讨论】:
标签: list tensorflow seq2seq