tensorflow学习中遇到的bug

1.Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.

这个错误是因为从 Keras 2.x 版本开始,推荐使用 Input 层来明确指定模型的输入形状,而不是在添加第一个非 Input 层时通过 input_shapeinput_dim 参数来指定。

#原代码
model=tf.keras.Sequential([
    
    #unit1 第一层卷积层
    tf.keras.layers.Conv2D(16,kernel_size=(3,3),padding="same",activation=tf.nn.relu,input(shape=(28, 28, 1))),

#***********************
#修改后的代码
model=tf.keras.Sequential([
    tf.keras.layers.Input(shape=(28, 28, 1)),  # 假设输入是一个 28x28 的灰度图像  
    
    #unit1 第一层卷积层
    tf.keras.layers.Conv2D(16,kernel_size=(3,3),padding="same",activation=tf.nn.relu),

#***********************

2.AttributeError: EagerTensor object has no attribute 'reshape'. If you are looking for numpy-related methods, please run the following: tf.experimental.numpy.experimental_enable_numpy_behavior()

#原代码
X_train=X_train.reshape(60000,28,28,1)
X_test=X_test.reshape(10000,28,28,1)
#修改代码
X_train=np.array(X_train).reshape(60000,28,28,1)
X_test=np.array(X_test).reshape(10000,28,28,1)

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值