python - 使用 InceptionV3 的 MNIST 的错误输入形状

标签 python image keras

我正在尝试将 MNIST 图像与许多分类器一起使用,但由于某种原因现在它会产生此错误。 (之前是正确的,但我已经更改了 InceptionV3 的来源)。 这是提供的错误:


InvalidArgumentError                      Traceback (most recent call last)
~\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\ops.py in _create_c_op(graph, node_def, inputs, control_inputs)
   1627  try:
-> 1628     c_op = c_api.TF_FinishOperation(op_desc)
   1629   except errors.InvalidArgumentError as e:

InvalidArgumentError: Negative dimension size caused by subtracting 3 from 1 for 'InceptionV3/InceptionV3/Mixed_6a/Branch_0/Conv2d_1a_1x1/Conv2D' (op: 'Conv2D') with input shapes: [?,1,1,288], [3,3,288,384].

在处理上述异常的过程中,又发生了一个异常:

ValueError                                Traceback (most recent call last)
<ipython-input-6-db92b294fe8d> in <module>
----> 1 fileImg1.play("Saliency")

~\OneDrive\Documenti\GitHub\cexplainer\src\Xlib.py in play(self, ex)
    193         if (ex not in self.dictImgModel):
    194             explainer = self.dictImgExplainer[ex]
--> 195             img = prepareImage(self.name,self.PATH,self.SHAPE_1,self.SHAPE_2,self.dataset,self.X_vec,self.y_vec,explainer,label)
    196             self.dictImgModel[ex] = img
    197 

~\OneDrive\Documenti\GitHub\cexplainer\src\algorithms\KDD.py in prepareImage(name, PATH, SHAPE_1, SHAPE_2, dataset, X_vec, y_vec, explainer, label)
    438                 with slim.arg_scope(inception.inception_v3_arg_scope()):
    439                     _, end_points = inception.inception_v3(processed_images, is_training=False,
--> 440                                                               num_classes=10)
    441                     # Restore the checkpoint
    442                     sess = tf.Session(graph=graph)

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\contrib\slim\python\slim\nets\inception_v3.py in inception_v3(inputs, num_classes, is_training, dropout_keep_prob, min_depth, depth_multiplier, prediction_fn, spatial_squeeze, reuse, scope)
    578           scope=scope,
    579           min_depth=min_depth,
--> 580           depth_multiplier=depth_multiplier)
    581 
    582       # Auxiliary Head logits 

有什么建议吗?

最佳答案

MNIST 是 1 channel 图像的集合。所有预训练模型均使用 3 channel (rgb) 图像。您可以通过重复 3 次单 channel 图像来绕过此冲突。

关于python - 使用 InceptionV3 的 MNIST 的错误输入形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55761616/

相关文章:

python - 为 Keras ANN 选择层/函数 - 线性回归

Python 正则表达式字符串组捕获

html - 如何平均设置 flex 元素高度

python - TimeDistributed 层的 CNN-LSTM 时间序列输入

python - 计算 keras 模型中的 PIL 逊系数时遇到 AttributeError : 'NoneType' object has no attribute '_inbound_nodes'

python - marshal.loads 函数不会将 *.pyc 内容加载到代码对象

python - pytube 有进度条功能吗?

javascript - 在 React Js 中更改图像 onClick

html - <img> 元素是 block 级还是行内级?

machine-learning - 如何在训练期间使用 lambda 函数更改层的激活