yhenon / keras-spp

Spatial pyramid pooling layers for keras
MIT License
394 stars 143 forks source link

Not working with tf.keras #25

Open ppurwar opened 4 years ago

ppurwar commented 4 years ago

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: `
sinclairnick commented 4 years ago

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