具有多个元素的数组的真值是不明确的。在图像分类问题中使用a.any()或a.all() [英] The truth value of an array with more than one element is ambiguous. Use a.any() or a.all(), in image classification problem

查看:119
本文介绍了具有多个元素的数组的真值是不明确的。在图像分类问题中使用a.any()或a.all()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用预定义的模型vgg16进行图像分类,验证数据的准确度达到89%,为提高模型的准确性,我进行了图像增强,但出现了一些错误。请帮助我如何适合该模型。
这是我的代码。

I doing image classification using predefined model vgg16, I got 89% accuracy in validation data, To increase the model accuracy, I did an image augmentation, but got some errors. please help me on how to fit for the model. here my code.

train_datagen = ImageDataGenerator(
        rescale=1./255,
        shear_range=0.2,
        zoom_range=0.2,
        horizontal_flip=True)

train_datagen.fit(X_train)

我使用的输入图像为64x64x3。
我是这样的健康模型。

I am using the input image are 64x64x3. I am a fit model like this.

history = model.fit_generator(
      train_datagen.flow(X_train,y_train),
      steps_per_epoch=(X_train)/32 ,
      epochs=30,
      validation_data=(X_test,y_test),
      validation_steps=(X_test)/32,
verbose=1)

Epoch 1/30
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-30-ff3a9aaa40da> in <module>()
      5       validation_data=(X_test,y_test),
      6       validation_steps=(X_test)/32,
----> 7 verbose=1)

/usr/local/lib/python3.6/dist-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
     89                 warnings.warn('Update your `' + object_name + '` call to the ' +
     90                               'Keras 2 API: ' + signature, stacklevel=2)
---> 91             return func(*args, **kwargs)
     92         wrapper._original_function = func
     93         return wrapper

/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
   1416             use_multiprocessing=use_multiprocessing,
   1417             shuffle=shuffle,
-> 1418             initial_epoch=initial_epoch)
   1419 
   1420     @interfaces.legacy_generator_methods_support

/usr/local/lib/python3.6/dist-packages/keras/engine/training_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
    178             steps_done = 0
    179             batch_index = 0
--> 180             while steps_done < steps_per_epoch:
    181                 generator_output = next(output_generator)
    182 

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


推荐答案

请参阅@ jmetz,@ suri,您将 validation_steps 参数设置为相同的问题,因为将其初始化为(X_test)/ 32 (可能不是标量)。
检查您的 validation_steps.shape / len(validation_steps)和您的 steps_per_epoch。形状 / len(steps_per_epoch)(取决于输入尺寸)。
它们必须是标量。

Referring to @jmetz, @suri you have the same issue with your validation_steps parameter, as you initialized it to (X_test)/32(probably not a scalar). Check your validation_steps.shape / len(validation_steps) and your steps_per_epoch.shape / len(steps_per_epoch)(depending on the input dimensions). They have to be scalars.

这篇关于具有多个元素的数组的真值是不明确的。在图像分类问题中使用a.any()或a.all()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆