Reputation: 81
This is a part of my code, before data augmentation, model.fit
was working, however after augmentation of data i'm getting this error;
AttributeError: module 'scipy.ndimage' has no attribute 'interpolation'
This is the list of all imported libraries;
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPool2D, Flatten, Dense
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import scipy.ndimage
import numpy
import random
import pathlib
import os
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import zipfile
import wget
# Create an augmented data generator
train_datagen_augmented = ImageDataGenerator(rescale=1/255.,
rotation_range=0.2,
width_shift_range=0.2,
height_shift_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
train_data_augmented = train_datagen_augmented.flow_from_directory(train_dir,
target_size=(224, 224),
batch_size=32,
class_mode='categorical')
# Clone the model (use the same architecture)
model_3 = tf.keras.models.clone_model(model)
# Compile the cloned model (same setup as used for model)
model_3.compile(loss="categorical_crossentropy",
optimizer=tf.keras.optimizers.Adam(),
metrics=["accuracy"])
# Fit the model
history_3 = model_3.fit(train_data_augmented, # use augmented data
epochs=5,
steps_per_epoch=len(train_data_augmented),
validation_data=test_data,
validation_steps=len(test_data))
Traceback (most recent call last):
File "", line 6, in history_3 = model_3.fit(train_data_augmented, # use augmented data
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\keras\engine\training.py", line 1133, in fit data_handler = data_adapter.get_data_handler(
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 1364, in get_data_handler return DataHandler(*args, **kwargs)
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 1154, in init self._adapter = adapter_cls(
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 932, in init super(KerasSequenceAdapter, self).init(
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 809, in init peek, x = self._peek_and_restore(x)
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 943, in _peek_and_restore return x[0], x
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\keras_preprocessing\image\iterator.py", line 65, in getitem return self._get_batches_of_transformed_samples(index_array)
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\keras_preprocessing\image\iterator.py", line 238, in _get_batches_of_transformed_samples x = self.image_data_generator.apply_transform(x, params)
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\keras_preprocessing\image\image_data_generator.py", line 863, in apply_transform x = apply_affine_transform(x, transform_parameters.get('theta', 0),
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\keras_preprocessing\image\affine_transformations.py", line 327, in apply_affine_transform channel_images = [ndimage.interpolation.affine_transform(
File "C:\Users\batuh\AppData\Roaming\Python\Python38\site-packages\keras_preprocessing\image\affine_transformations.py", line 327, in channel_images = [ndimage.interpolation.affine_transform(
AttributeError: module 'scipy.ndimage' has no attribute 'interpolation'
Upvotes: 0
Views: 990
Reputation: 81
I found the problem. Problem was that scipy
was missing in my anaconda virtual environment. I thought scipy
was installed when I saw;
AttributeError: module 'scipy.ndimage' has no attribute 'interpolation'
Thanks for the tip @simpleApp. And I'm sorry to bother you with the mistake of absent-mindedness... Solution is the installing scipy
.
Upvotes: 0