1

I am trying to use the xception model for a transfer learning task. I understand that it needs the minimum input shape of image to be (71, 71, 3) when downloading it with option include_top=False.

The issues I am facing is that when I try to reshape my data from (48,48,3) to (71,71,3) I am going in to RAM issues and my system gets restarted. Instead of reshaping the data outside I think of reshaping it within the network architecture. When I try to do that I have the follow error..

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-44-a448922440e7> in <module>()
      1 model = Sequential()
      2 #model.add(Input(shape=(48,48,3)))
----> 3 model.add(tf.keras.layers.Reshape((71,71,3), input_shape=(48,48,3)))
      4 #model.add(ReformatImage(71,71))
      5 model.add(conv_base)

8 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/core.py in _fix_unknown_dimension(self, input_shape, output_shape)
    534       output_shape[unknown] = original // known
    535     elif original != known:
--> 536       raise ValueError(msg)
    537     return output_shape
    538 

ValueError: total size of new array must be unchanged, input_shape = [48, 48, 3], output_shape = [71, 71, 3]

my code is as below


from tensorflow.keras.applications import Xception
conv_base = Xception(weights='imagenet',include_top=False,input_shape=(71,71,3))

conv_base.trainable = False

model = Sequential()
#model.add(Input(shape=(48,48,3)))
model.add(tf.keras.layers.Reshape((71,71,3), input_shape=(48,48,3)))
#model.add(ReformatImage(71,71))
model.add(conv_base)
model.add(Flatten())
model.add(Dense(1024, activation='relu'))
model.add(Dense(1024, activation='relu'))
model.add(BatchNormalization())
model.add(Dense(10, activation='softmax'))

model.summary()

can someone please point me to right direction so that I can resolve this issue?

2 Answers 2

1

Reshape 'arranges' an input data from its inut shape to an output shape, so it doesn't create new data. Here you ask to arrange a (48x48x3) tensor into a (71x71x3) tensor, so it is not possible.

To do it you have to preprocess your images with resize functions : cv2.resize, skimage.transform.resize, tf.keras.preprocessing.ImageDataGenerator...

Sign up to request clarification or add additional context in comments.

Comments

0

You can use tf.keras.layers.experimental.preprocessing.Resizing:

tf.keras.layers.experimental.preprocessing.Resizing(48, 48)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.