Как решить ошибку float() argument must be a string or a number, not 'JpegImageFile' keras?

Я использую keras для обучения модели (theano backend). Сделал собственный датасет, используя расширение Fatkun и гугл-картинки. Ссылка на архив с датасетом: https://drive.google.com/file/d/1G0GRGk5Wc0mL6jiQ0KsJrXQB4QCm8ikD/view?usp=sharing

Основной код:

import numpy as np
from PIL import Image
from matplotlib import pyplot as plt
import os
import keras 
import joblib
from keras.preprocessing.image import ImageDataGenerator


train_images = 'C:\\Users\\Администратор\\AppData\\Local\\Programs\\Python\\Python36-32\\train_images'

model = keras.Sequential([
    keras.layers.Flatten(input_shape=(36, 36, 3)),
    keras.layers.Dense(64, activation='relu'),
    keras.layers.Dropout(0.5),
    keras.layers.Dense(1, activation='sigmoid')
])

model.compile(optimizer='adam',
              loss='binary_crossentropy',
              metrics=['accuracy'])

datagen = ImageDataGenerator(rescale = 1. /255)

train_generator = datagen.flow_from_directory(
  train_images,
  target_size = (36,36),
  batch_size = 4,
  class_mode = 'binary')

model.fit(np.array(train_generator), epochs=10, validation_split = 0.1)

Сообщение об ошибке:

C:\Users\Администратор>C:\Users\Администратор\AppData\Local\Programs\Python\Pyth
on36-32\image_guess.py
Using Theano backend.
    WARNING (theano.configdefaults): g++ not available, if using conda: `conda insta
    ll m2w64-toolchain`
    C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\lib\site-packag
    es\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c+
    + compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandat
    ory
      warnings.warn("DeprecationWarning: there is no c++ compiler."
    WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to exe
    cute optimized C-implementations (for both CPU and GPU) and will default to Pyth
    on implementations. Performance will be severely degraded. To remove this warnin
    g, set Theano flags cxx to an empty string.
    WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS fu
    nctions.
    Found 336 images belonging to 2 classes.
    Traceback (most recent call last):
      File "C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\image_g
    uess.py", line 32, in <module>
        model.fit(np.array(train_generator), epochs=10, validation_split = 0.1)
      File "C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\lib\sit
    e-packages\keras_preprocessing\image\iterator.py", line 104, in __next__
        return self.next(*args, **kwargs)
      File "C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\lib\sit
    e-packages\keras_preprocessing\image\iterator.py", line 116, in next
        return self._get_batches_of_transformed_samples(index_array)
      File "C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\lib\sit
    e-packages\keras_preprocessing\image\iterator.py", line 231, in _get_batches_of_
    transformed_samples
        x = img_to_array(img, data_format=self.data_format)
      File "C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\lib\sit
    e-packages\keras_preprocessing\image\utils.py", line 309, in img_to_array
        x = np.asarray(img, dtype=dtype)
      File "C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\lib\sit
    e-packages\numpy\core\_asarray.py", line 83, in asarray
        return array(a, dtype, copy=False, order=order)
    TypeError: float() argument must be a string or a number, not 'JpegImageFile'

Ответы (0 шт):