'NoneType' object has no attribute XXX
See original GitHub issueAs title, I followed the example: cifar10_cnn.py, using a subset of cifar10, loading data without using (X_train, y_train), (X_test, y_test) = cifar10.load_data()
but using numpy to parse the data to be like <type 'numpy.ndarray'> shape: (5000, 32, 32, 3)
.
Then I trained the network by setting data_augmentation = True
, the training part of code was same as the example
# convert class vectors to binary class matrices
Y_train = np_utils.to_categorical(y_train, nb_classes)
Y_test = np_utils.to_categorical(y_test, nb_classes)
model = Sequential()
model.add(Convolution2D(32, 3, 3, border_mode='same',
input_shape=X_train.shape[1:]))
model.add(Activation('relu'))
model.add(Convolution2D(32, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Convolution2D(64, 3, 3, border_mode='same'))
model.add(Activation('relu'))
model.add(Convolution2D(64, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))
# let's train the model using SGD + momentum (how original).
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy',
optimizer=sgd,
metrics=['accuracy'])
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255
if not data_augmentation:
print('Not using data augmentation.')
model.fit(X_train, Y_train,
batch_size=batch_size,
nb_epoch=nb_epoch,
validation_data=(X_test, Y_test),
shuffle=True)
else:
print('Using real-time data augmentation.')
# this will do preprocessing and realtime data augmentation
datagen = ImageDataGenerator(
featurewise_center=False, # set input mean to 0 over the dataset
samplewise_center=False, # set each sample mean to 0
featurewise_std_normalization=False, # divide inputs by std of the dataset
samplewise_std_normalization=False, # divide each input by its std
zca_whitening=False, # apply ZCA whitening
rotation_range=0, # randomly rotate images in the range (degrees, 0 to 180)
width_shift_range=0.1, # randomly shift images horizontally (fraction of total width)
height_shift_range=0.1, # randomly shift images vertically (fraction of total height)
horizontal_flip=True, # randomly flip images
vertical_flip=False) # randomly flip images
# compute quantities required for featurewise normalization
# (std, mean, and principal components if ZCA whitening is applied)
datagen.fit(X_train)
# fit the model on the batches generated by datagen.flow()
model.fit_generator(datagen.flow(X_train, Y_train,
batch_size=batch_size),
samples_per_epoch=X_train.shape[0],
nb_epoch=nb_epoch,
validation_data=(X_test, Y_test))
but it threw the error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 435, in data_generator_task
generator_output = next(generator)
File "/usr/local/lib/python2.7/dist-packages/keras/preprocessing/image.py", line 496, in next
x = self.image_data_generator.random_transform(x.astype('float32'))
File "/usr/local/lib/python2.7/dist-packages/keras/preprocessing/image.py", line 362, in random_transform
fill_mode=self.fill_mode, cval=self.cval)
File "/usr/local/lib/python2.7/dist-packages/keras/preprocessing/image.py", line 108, in apply_transform
final_offset, order=0, mode=fill_mode, cval=cval) for x_channel in x]
AttributeError: 'NoneType' object has no attribute 'interpolation'
and the error was different sometimes:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 433, in data_generator_task
generator_output = next(generator)
File "/usr/local/lib/python2.7/dist-packages/keras/preprocessing/image.py", line 496, in next
x = self.image_data_generator.random_transform(x.astype('float32'))
File "/usr/local/lib/python2.7/dist-packages/keras/preprocessing/image.py", line 360, in random_transform
transform_matrix = transform_matrix_offset_center(transform_matrix, h, w)
TypeError: 'NoneType' object is not callable
Any help would be very nice to me, thanks.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:18 (3 by maintainers)
Top Results From Across the Web
Python Image Library: AttributeError: 'NoneType' object has ...
With googling I found this comment on SO, stating that PIL is sometimes 'lazy' and 'forgets' to load after opening.
Read more >'NoneType' object has no attribute 'val'类型错误分析
AttributeError : 'NoneType' object has no attribute 'text' 出处difficult = obj.find('difficult').text 方案错误提示的是空元素,没有对应的属性。 < ...
Read more >Exceptions and common tracebacks
You are inhering schema in Archetypes, but you do not inherit the class itself. AttributeError: 'FilesystemResourceDirectory' object has no attribute ' ...
Read more >AttributeError: 'NoneType' object has no attribute 'get_items'
We run CS on a SLURM cluster. All the job data seems to be there. The folder is writable by the cryosparc instance...
Read more >error on custom module AttributeError: 'NoneType'
'ir_actions': AttributeError: 'NoneType' object has no attribute '_table'. __openerp__. { 'name': 'Project Management Extension', 'version': '0.1', ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same here during
model.save()
. Keras 2.1.4 backed by TensorFlow 1.5.0 and usedmodel = multi_gpu_model(model)
@lukeyeager I’m having the same problem in Keras 2.1.2. Unfortunately the code of this version is different from 1.2.0 and I couldn’t find
thread.daemon
as you suggested. Do you have a solution for 2.1.2 please? Thanks in advance.