Tensorflow搭建卷积神经网络问题及解决

本文针对使用Tensorfolw搭建卷积神经网络遇到的问题进行解析和解决。

  • 问题1
ValueError: Only call `softmax_cross_entropy_with_logits` with named arguments (labels=..., logits=..., ...)

【原因】

#softmax_cross_entropy_with_logits未指定logits和labels参数
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y))

【解决方案】

cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y))
  • 问题2
InvalidArgumentError (see above for traceback): logits and labels must be same size: logits_size=[32,10] labels_size=[128,10]
	 [[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape_3, Reshape_4)]]

【原因】

logits和labels向量尺寸不一致。

【解决方案】
重新计算卷积层和池化层输出节点矩阵。
使用0填充,输出节点矩阵仅与步长有关, o u t p u t s i z e = i n p u t s i z e s t r i d e s output_{size}=\frac{input_{size}}{strides} outputsize=stridesinputsize
不使用0填充,输出节点矩阵和步长、卷积核有关, o u t p u t s i z e = i n p u t s i z e − k e r n e l s i z e s t r i d e s + 1 output_{size}=\frac{input_{size}-kernel_{size}}{strides}+1 outputsize=stridesinputsizekernelsize+1


[参考文献]
[1]https://www.jianshu.com/p/65be1d48e8f2


  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天然玩家

坚持才能做到极致

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值