ValueError: When setting `include_top=True` and loading `imagenet` weights, `input_shape` should be (224, 224, 3).
from keras.preprocessing import image import keras.applications.vgg19 as vgg19 model = vgg19.VGG19(weights='imagenet', input_shape=(64, 64, 3)) model.summary()
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-6-7f2e82711ae3> in <module>() 2 import keras.applications.vgg19 as vgg19 3 ----> 4 model = vgg19.VGG19(weights='imagenet', input_shape=(64, 64, 3)) 5 model.summary() /usr/local/lib/python3.6/dist-packages/keras/applications/__init__.py in wrapper(*args, **kwargs) 26 kwargs['models'] = models 27 kwargs['utils'] = utils ---> 28 return base_fun(*args, **kwargs) 29 30 return wrapper /usr/local/lib/python3.6/dist-packages/keras/applications/vgg19.py in VGG19(*args, **kwargs) 9 @keras_modules_injection 10 def VGG19(*args, **kwargs): ---> 11 return vgg19.VGG19(*args, **kwargs) 12 13 /usr/local/lib/python3.6/dist-packages/keras_applications/vgg19.py in VGG19(include_top, weights, input_tensor, input_shape, pooling, classes, **kwargs) 97 data_format=backend.image_data_format(), 98 require_flatten=include_top, ---> 99 weights=weights) 100 101 if input_tensor is None: /usr/local/lib/python3.6/dist-packages/keras_applications/imagenet_utils.py in _obtain_input_shape(input_shape, default_size, min_size, data_format, require_flatten, weights) 290 'and loading `imagenet` weights, ' 291 '`input_shape` should be ' + --> 292 str(default_shape) + '.') 293 return default_shape 294 if input_shape: ValueError: When setting `include_top=True` and loading `imagenet` weights, `input_shape` should be (224, 224, 3).
imagenetのウェイトを使うとき、input_shapeはデフォルトのみ
if weights == 'imagenet' and require_flatten: if input_shape is not None: if input_shape != default_shape: <==================ここで、エラーになる raise ValueError('When setting `include_top=True` ' 'and loading `imagenet` weights, ' '`input_shape` should be ' + str(default_shape) + '.') return default_shape if input_shape: if data_format == 'channels_first': if input_shape is not None: if len(input_shape) != 3: raise ValueError( '`input_shape` must be a tuple of three integers.') if input_shape[0] != 3 and weights == 'imagenet': raise ValueError('The input must have 3 channels; got ' '`input_shape=' + str(input_shape) + '`') if ((input_shape[1] is not None and input_shape[1] < min_size) or (input_shape[2] is not None and input_shape[2] < min_size)): raise ValueError('Input size must be at least ' + str(min_size) + 'x' + str(min_size) + '; got `input_shape=' + str(input_shape) + '`')
keras-applications/imagenet_utils.py at master · keras-team/keras-applications · GitHub