tensorflow2 运行时报错 AttributeError: ‘list‘ object has no attribute ‘_in_graph_mode‘
作者:互联网
原代码
variavles = [convc_net.trainable_variables + fc_net.trainable_variables]
for epoch in range(30):
for step, (x, y), in enumerate(db_train):
with tf.GradientTape() as tape:
out = convc_net(x)
out = tf.reshape(out, shape=[-1, 512])
print(out.shape)
y_ = fc_net(out)
print(y_.shape)
y_onehot = tf.one_hot(y, depth=100)
print(y_onehot.shape)
loss = tf.reduce_mean(tf.losses.categorical_crossentropy(y_, y_onehot))
grads = tape.gradient(loss, variavles)
optimizer.apply_gradients(zip(grads, variavles))
报错
AttributeError: 'list' object has no attribute '_in_graph_mode'
就是这一行variavles = [convc_net.trainable_variables + fc_net.trainable_variables]
去掉中括号
标签:tensorflow2,no,attribute,variables,trainable,shape,tf,net,out 来源: https://blog.csdn.net/weixin_48306625/article/details/122507117