invalid argument什么意思python_InvalidArgumentError:无法使用形状为[32]的张量更新形状为[]的变量...

我试图从神经结构学习开始,但是当我运行页面上给出的示例进行测试时,我得到以下错误

我尝试过压缩维度,我尝试过不同版本的tensorflow——我对tensorflow还是相当陌生的,所以在这一点上我真的是在猜测。在# Create a base model -- sequential, functional, or subclass.

model = tf.keras.Sequential([

tf.keras.Input((28, 28), name='feature'),

tf.keras.layers.Flatten(),

tf.keras.layers.Dense(128, activation=tf.nn.relu),

tf.keras.layers.Dense(10, activation=tf.nn.softmax)

])

# Wrap the model with adversarial regularization.

adv_config = nsl.configs.make_adv_reg_config(multiplier=0.2, adv_step_size=0.05)

adv_model = nsl.keras.AdversarialRegularization(model, adv_config=adv_config)

# Compile, train, and evaluate.

adv_model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])

#let us now fit the model

adv_model.fit({'feature': x_train, 'label': y_train}, batch_size=32, epochs=5)

W0906 13:48:30.427690 140388427564928 training_utils.py:1101] Output output_1 missing from loss dictionary. We assume this was done on purpose. The fit and evaluate APIs will not be expecting any data to be passed to output_1.

Epoch 1/5

---------------------------------------------------------------------------

InvalidArgumentError Traceback (most recent call last)

in ()

----> 1 adv_model.fit({'feature': x_train, 'label': y_train}, batch_size=32, epochs=5)

3 frames

/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in __call__(self, *args, **kwargs)

1456 ret = tf_session.TF_SessionRunCallable(self._session._session,

1457 self._handle, args,

-> 1458 run_metadata_ptr)

1459 if run_metadata:

1460 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

InvalidArgumentError: Cannot update variable with shape [] using a Tensor with shape [32], shapes must be equal.

[[{{node AdversarialRegularization_1/AssignAddVariableOp_2}}]]

这个模型应该训练,我从中得到了一些准确性。我不知道我的代码中的问题来自哪里。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值