title: "Cats vs Dogs" artificial neural network Tensorflow model.fit problems
body: <p>I am trying to learn the machine to recognize a cat or a dog when the algorithm is shown a picture of either a cat or dog. I am using Spyder as IDE, and Tensorflow.</p>
  <p>We are supposed to run this code to train the AI:</p>
  <pre><code>#%%
  from tensorflow.keras import layers
  from tensorflow.keras import models
  
  model = models.Sequential()
  
  #%%
  # 32 filters with 3x3 pixel kernels and ReLU activation for 150x150 RGB (= 3-channel) images
  model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3)))
  
  # Downsample by picking max input from every 2x2 window of previous neurons
  model.add(layers.MaxPooling2D((2, 2))) 
  
  # Next layer of filters
  model.add(layers.Conv2D(64, (3, 3), activation='relu'))
  
  # More downsampling (important to reduce network size/complexity)
  model.add(layers.MaxPooling2D((2, 2))) 
  model.add(layers.Conv2D(128, (3, 3), activation='relu')) 
  model.add(layers.MaxPooling2D((2, 2))) 
  model.add(layers.Conv2D(128, (3, 3), activation='relu')) 
  model.add(layers.MaxPooling2D((2, 2)))
  
  #%%
  model.add(layers.Flatten()) 
  model.add(layers.Dense(512, activation='relu')) 
  model.add(layers.Dense(1, activation='sigmoid'))
  
  #%%
  from tensorflow.keras import optimizers
  model.compile(loss='binary_crossentropy',
                optimizer=optimizers.RMSprop(lr=1e-4),
                metrics=['acc'])
  
  #%%
  from tensorflow.keras.preprocessing.image import ImageDataGenerator
  
  train_datagen = ImageDataGenerator(rescale=1./255)
  test_datagen = ImageDataGenerator(rescale=1./255)
  
  train_dir = &quot;C:\\Users\\Nicholai\\Desktop\\dogs-vs-cats\small\\train&quot;
  validation_dir = &quot;C:\\Users\\Nicholai\\Desktop\\dogs-vs-cats\\small\\val&quot;
  
  im_per_batch = 20 
  im_size = (150,150) # Same as number of inputs in the network
  
  train_generator = train_datagen.flow_from_directory(
      train_dir,
      target_size=im_size,
      batch_size=im_per_batch,
      class_mode='binary')
  
  validation_generator = test_datagen.flow_from_directory(
      validation_dir,
      target_size=im_size,
      batch_size=im_per_batch,
      class_mode='binary')
  
  #%%
  num_epochs = 30
  history = model.fit_generator(
      train_generator,
      steps_per_epoch = train_generator.n // im_per_batch,
      epochs=num_epochs,
      validation_data = validation_generator,
      validation_steps = validation_generator.n // im_per_batch)
  
  #%%
  model.save('dogs-vs-cats-1.h5')
  from keras.models import load_model
  model = load_model('dogs-vs-cats-1.h5')
  </code></pre>
  <p>I get this error:</p>
  <pre><code>C:\Users\Nicholai\.spyder-py3\temp.py:61: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
    history = model.fit_generator(
  Traceback (most recent call last):
  
    File &quot;C:\Users\Nicholai\.spyder-py3\temp.py&quot;, line 61, in &lt;module&gt;
      history = model.fit_generator(
  
    File &quot;C:\Users\Nicholai\anaconda3\envs\CNN\lib\site-packages\keras\engine\training.py&quot;, line 2016, in fit_generator
      return self.fit(
  
    File &quot;C:\Users\Nicholai\anaconda3\envs\CNN\lib\site-packages\keras\utils\traceback_utils.py&quot;, line 67, in error_handler
      raise e.with_traceback(filtered_tb) from None
  
    File &quot;C:\Users\Nicholai\anaconda3\envs\CNN\lib\site-packages\keras_preprocessing\image\affine_transformations.py&quot;, line 281, in apply_affine_transform
      raise ImportError('Image transformations require SciPy. '
  
  ImportError: Image transformations require SciPy. Install SciPy.
  </code></pre>
  <p>I understand that Tensorflow newer than 2.0 can use model.fit() instead of model.fit_generator(). SciPy is installed  When I try that I still get errors like this:</p>
  <pre><code>    Traceback (most recent call last):
  
    File &quot;C:\Users\Nicholai\.spyder-py3\temp.py&quot;, line 61, in &lt;module&gt;
      history = model.fit(
  
    File &quot;C:\Users\Nicholai\anaconda3\envs\CNN\lib\site-packages\keras\utils\traceback_utils.py&quot;, line 67, in error_handler
      raise e.with_traceback(filtered_tb) from None
  
    File &quot;C:\Users\Nicholai\anaconda3\envs\CNN\lib\site-packages\keras_preprocessing\image\affine_transformations.py&quot;, line 281, in apply_affine_transform
      raise ImportError('Image transformations require SciPy. '
  </code></pre>
  <p>What am I doing wrong?</p>