Node: 'model/swin_transformer/tf_swin_model/swin/encoder/layers.1/blocks.0/Reshape_33' Input to reshape is a tensor with 3763200 values, but the requested shape requires a multiple of 20384
Hi, i used Swin as feature Extractor like :
class SwinTransformer(tf.keras.Model):
def init(self, model_name="microsoft/swin-tiny-patch4-window7-224"):
super(SwinTransformer, self).init()
self.transformer = TFSwinModel.from_pretrained(model_name,
use_auth_token="hf_token")
self.global_avg_pooling = tf.keras.layers.GlobalAveragePooling1D()
def call(self, inputs):
x = self.transformer(inputs)
x = x.last_hidden_state
x = self.global_avg_pooling(x)
return x
and the input size is (batch_size, 3,224,224); train_dataset = train_dataset.shuffle(1000).batch(25,drop_remainder=True)
Here is the problem:
when training the model, it only work in specific batch size like 1,2,3,9,30. Other batch size would cause problem like below, it's like there are some problem in the swin window, but it's weird ? do anyone know what is going on here and how to fix this, appreciate that a lot~ :
File "/home/yilei/MT/video_sync/models/featureExtractor.py", line 126, in call
x = self.transformer(inputs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/engine/training.py", line 557, in call
return super().call(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/engine/base_layer.py", line 1097, in call
outputs = call_fn(inputs, *args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 96, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/transformers/modeling_tf_utils.py", line 1198, in run_call_with_unpacked_inputs
"""
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/transformers/models/swin/modeling_tf_swin.py", line 1213, in call
swin_outputs = self.swin(
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/engine/base_layer.py", line 1097, in call
outputs = call_fn(inputs, *args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 96, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/transformers/modeling_tf_utils.py", line 1198, in run_call_with_unpacked_inputs
"""
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/transformers/models/swin/modeling_tf_swin.py", line 1137, in call
encoder_outputs = self.encoder(
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/engine/base_layer.py", line 1097, in call
outputs = call_fn(inputs, *args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 96, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/transformers/models/swin/modeling_tf_swin.py", line 910, in call
for i, layer_module in enumerate(self.layers):
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/transformers/models/swin/modeling_tf_swin.py", line 913, in call
layer_outputs = layer_module(
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/engine/base_layer.py", line 1097, in call
outputs = call_fn(inputs, *args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 96, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/transformers/models/swin/modeling_tf_swin.py", line 842, in call
for i, layer_module in enumerate(self.blocks):
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/transformers/models/swin/modeling_tf_swin.py", line 845, in call
layer_outputs = layer_module(
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/engine/base_layer.py", line 1097, in call
outputs = call_fn(inputs, *args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 96, in error_handler
return fn(*args, **kwargs)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/transformers/models/swin/modeling_tf_swin.py", line 769, in call
shifted_windows = window_reverse(attention_windows, window_size, height_pad, width_pad)
File "/home/yilei/anaconda3/envs/MT_tf/lib/python3.7/site-packages/transformers/models/swin/modeling_tf_swin.py", line 243, in window_reverse
windows = tf.reshape(
Node: 'model/swin_transformer/tf_swin_model/swin/encoder/layers.1/blocks.0/Reshape_33'
Input to reshape is a tensor with 3763200 values, but the requested shape requires a multiple of 20384
[[{{node model/swin_transformer/tf_swin_model/swin/encoder/layers.1/blocks.0/Reshape_33}}]] [Op:__inference_train_function_171382]
ERROR conda.cli.main_run:execute(49): conda run python /home/yilei/MT/video_sync/exp_loss/train_disR.py
failed. (See above for error)