[英]Xception Model Transfer Learning Input Image - Tensorflow
I am trying to use the xception
model for a transfer learning task.我正在尝试使用
xception
model 进行迁移学习任务。 I understand that it needs the minimum input shape of image to be (71, 71, 3)
when downloading it with option include_top=False
.我知道在使用选项
include_top=False
下载图像时,它需要图像的最小输入形状为(71, 71, 3)
。
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.我面临的问题是,当我尝试将数据从
(48,48,3)
重塑为(71,71,3)
时,我会遇到 RAM 问题并且我的系统会重新启动。 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?有人可以指出我正确的方向,以便我可以解决这个问题吗?
Reshape
'arranges' an input data from its inut shape to an output shape, so it doesn't create new data. Reshape
将输入数据从其 inut 形状“排列”为 output 形状,因此它不会创建新数据。 Here you ask to arrange a (48x48x3) tensor into a (71x71x3) tensor, so it is not possible.在这里,您要求将(48x48x3)张量排列成(71x71x3)张量,所以这是不可能的。
To do it you have to preprocess your images with resize functions: cv2.resize
, skimage.transform.resize
, tf.keras.preprocessing.ImageDataGenerator
...为此,您必须使用调整大小函数对图像进行预处理:
cv2.resize
、 skimage.transform.resize
、 tf.keras.preprocessing.ImageDataGenerator
...
You can use tf.keras.layers.experimental.preprocessing.Resizing
:您可以使用
tf.keras.layers.experimental.preprocessing.Resizing
:
tf.keras.layers.experimental.preprocessing.Resizing(48, 48)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.