ValueError: 多于一个元素的数组的真值含糊不清。使用a.any()或a.all() , 如何解决?

问题描述 投票:0回答:1

我想用tensorflow做一个剪刀石头布的游戏,所以我想输入一个图像,然后输出'纸','剪刀',或者'石头'取决于这个图像,但是我有一个问题要解决它 => 一个数组中有多个元素的真值是模糊的,请使用a.any(或a.all()。使用a.any()或a.all(),所以如何解决?

这是我的代码

import numpy as np
from google.colab import files
from keras.preprocessing import image
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
%matplotlib inline

uploaded = files.upload()

for fn in uploaded.keys():

  # predicting images
  path = fn
  img = image.load_img(path, target_size=(150,150))
  imgplot = plt.imshow(img)
  x = image.img_to_array(img)
  x = np.expand_dims(x, axis=0)

  images = np.vstack([x])
  classes = model.predict(images, batch_size=10)

  print(fn)
  if classes==0:
    print('paper')
  elif classes==1:
    print('scissors')
  else:
    print('rock')

结果是这样的错误

    ValueError                                Traceback (most recent call last)
<ipython-input-69-ca5bd193fb08> in <module>()
     23 
     24   print(fn)
---> 25   if classes==0:
     26     print('paper')
     27   elif classes==1:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

指导我在我的初学者的家伙plss😊 Thx。

python numpy tensorflow
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.