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]

去掉中括号

上一篇:段寄存器属性的探测


下一篇:微信朋友圈广告的赢家是他们