keras-spp icon indicating copy to clipboard operation
keras-spp copied to clipboard

Not working with tf.keras

Open ppurwar opened this issue 5 years ago • 1 comments

I tried the given example with tf 1.14.

` from tensorflow.keras.models import Sequential from keras_spp.spp.SpatialPyramidPooling import SpatialPyramidPooling from keras.layers import Convolution2D, Activation, MaxPooling2D, Dense

model = Sequential()

model.add(Convolution2D(32, 3, 3, border_mode='same', input_shape=(3, None, None))) model.add(Activation('relu')) model.add(Convolution2D(32, 3, 3)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) 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(SpatialPyramidPooling([1, 2, 4])) model.add(Dense(num_classes)) model.add(Activation('softmax'))`

Error received:

`--------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () 6 7 # uses theano ordering. Note that we leave the image size as None to allow multiple image sizes ----> 8 model.add(Convolution2D(32, 3, 3, border_mode='same', input_shape=(3, None, None))) 9 model.add(Activation('relu')) 10 model.add(Convolution2D(32, 3, 3))

~/anaconda3/envs/py3_tf14/lib/python3.6/site-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs) 455 self._self_setattr_tracking = False # pylint: disable=protected-access 456 try: --> 457 result = method(self, *args, **kwargs) 458 finally: 459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access

~/anaconda3/envs/py3_tf14/lib/python3.6/site-packages/tensorflow/python/keras/engine/sequential.py in add(self, layer) 152 raise TypeError('The added layer must be ' 153 'an instance of class Layer. ' --> 154 'Found: ' + str(layer)) 155 156 tf_utils.assert_no_legacy_layers([layer])

TypeError: The added layer must be an instance of class Layer. Found: <keras.layers.convolutional.Conv2D object at 0x7f8057c3ddd8> `

ppurwar avatar Mar 13 '20 10:03 ppurwar

Hey @ppurwar, not sure if this is still relevant to you, but I've posted my implementation/modifications which make the SPP compatible with tf.keras.

See #26

sinclairnick avatar Apr 30 '20 00:04 sinclairnick