0
votes

I have a problem with AveragePooling2D:

from keras.models import Sequential, Model
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D, ZeroPadding2D, GlobalAveragePooling2D, AveragePooling2D
import keras.backend as K
import math

K.clear_session()

base_model = InceptionV3(weights='imagenet', include_top=False, input_tensor=Input(shape=(150, 150, 3)))
x = base_model.outputs
x = AveragePooling2D(pool_size=(8, 8))(x)

I get an error:


AttributeError Traceback (most recent call last) in ()

~/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py in call(self, inputs, **kwargs) 617 618 # Actually call the layer, collecting output(s), mask(s), and shape(s). --> 619 output = self.call(inputs, **kwargs) 620 output_mask = self.compute_mask(inputs, previous_mask) 621

~/anaconda3/lib/python3.6/site-packages/keras/layers/pooling.py in call(self, inputs) 156 strides=self.strides, 157 padding=self.padding, --> 158 data_format=self.data_format) 159 return output 160

~/anaconda3/lib/python3.6/site-packages/keras/layers/pooling.py in _pooling_function(self, inputs, pool_size, strides, padding, data_format) 273 padding, data_format): 274 output = K.pool2d(inputs, pool_size, strides, --> 275 padding, data_format, pool_mode='avg') 276 return output 277

~/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in pool2d(x, pool_size, strides, padding, data_format, pool_mode)
3643 raise ValueError('Unknown data_format: ' + str(data_format)) 3644 -> 3645 x, tf_data_format = _preprocess_conv2d_input(x, data_format) 3646 padding = _preprocess_padding(padding)
3647 if tf_data_format == 'NHWC':

~/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in _preprocess_conv2d_input(x, data_format) 3202 A tensor. 3203 """ -> 3204 if dtype(x) == 'float64': 3205 x = tf.cast(x, 'float32') 3206 tf_data_format = 'NHWC'

~/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in dtype(x) 640 ``` 641 """ --> 642 return x.dtype.base_dtype.name 643 644

AttributeError: 'list' object has no attribute 'dtype'

but if I print(x) this is the result I get:

tf.Tensor 'mixed10/concat:0' shape=(?, 3, 3, 2048) dtype=float32

So basically "x" has a dtype which is float32 but AveragePooling2D doesn't recognize it as I understand it correctly. Can anyone point me out where to look to solve this problem?

1

1 Answers

1
votes

Just remove the 's':

x = base_model.output

That's because outputs gives you a list of outputs. As you only have one in this case, output works fine for you. You'd have to select from this list otherwise.