英文:
TypeError: call() got an unexpected keyword argument 'use_causal_mask' ---> getting this error on flickr8k/flickr30k dataset
问题
错误
TypeError Traceback (most recent call last)
/tmp/ipykernel_23/1382744270.py in <module>
2 image_path = tf.keras.utils.get_file('surf.jpg', origin=image_url)
3 image = load_image(image_path)
----> 4 model.simple_gen(image, temperature=1, max_run=1)
/tmp/ipykernel_23/644194926.py in simple_gen(self, image, temperature, max_run)
7 for n in range(max_run):
8 print("interation", n)
----> 9 preds = self((img_features, tokens)).numpy() # (batch, sequence, vocab)
10 preds = preds[:,-1, :] #(batch, vocab)
11 if temperature==0:
/opt/conda/lib/python3.7/site-packages/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
1035 with autocast_variable.enable_auto_cast_variables(
1036 self._compute_dtype_object):
-> 1037 outputs = call_fn(inputs, *args, **kwargs)
1038
1039 if self._activity_regularizer:
/tmp/ipykernel_23/4251248884.py in call(self, inputs)
20 # Look at the image
21 for dec_layer in self.decoder_layers:
---> 22 txt = dec_layer(inputs=(image, txt))
23
24 txt = self.output_layer(txt)
/opt/conda/lib/python3.7/site-packages/keras/engine/base_layer.py in __call(self, *args, **kwargs)
1035 with autocast_variable.enable_auto_cast_variables(
1036 self._compute_dtype_object):
-> 1037 outputs = call_fn(inputs, *args, **kwargs)
1038
1039 if self._activity_regularizer:
/tmp/ipykernel_23/725126540.py in call(self, inputs, training)
16
17 # 文本输入
---> 18 out_seq = self.self_attention(out_seq)
19
20 out_seq = self.cross_attention(out_seq, in_seq)
/opt/conda/lib/python3.7/site-packages/keras/engine/base_layer.py in __call(self, *args, **kwargs)
1035 with autocast_variable.enable_auto_cast_variables(
1036 self._compute_dtype_object):
-> 1037 outputs = call_fn(inputs, *args, **kwargs)
1038
1039 if self._activity_regularizer:
/tmp/ipykernel_23/1379568068.py in call(self, x)
8
9 def call(self, x):
---> 10 attn = self.mha(query=x, value=x, use_causal_mask=True)
11 print("mask", attn, "end_mask")
12 x = self.add([x, attn])
/opt/conda/lib/python3.7/site-packages/keras/engine/base_layer.py in __call(self, *args, **kwargs)
1035 with autocast_variable.enable_auto_cast_variables(
1036 self._compute_dtype_object):
-> 1037 outputs = call_fn(inputs, *args, **kwargs)
1038
1039 if self._activity_regularizer:
TypeError: call() got an unexpected keyword argument 'use_causal_mask'
代码
用于图像字幕的TensorFlow教程(使用InceptionV3而不是MobileNetV3)
数据集
来自Kaggle的Filckr8k数据集 -> https://www.kaggle.com/datasets/adityajn105/flickr8k
该错误是由因果自注意力层的多头注意力函数引发的。
我已尝试从call方法中删除use_causal_mask参数,似乎可以正常工作。
英文:
Error
TypeError Traceback (most recent call last)
/tmp/ipykernel_23/1382744270.py in <module>
2 image_path = tf.keras.utils.get_file('surf.jpg', origin=image_url)
3 image = load_image(image_path)
----> 4 model.simple_gen(image, temperature=1, max_run=1)
/tmp/ipykernel_23/644194926.py in simple_gen(self, image, temperature, max_run)
7 for n in range(max_run):
8 print("interation", n)
----> 9 preds = self((img_features, tokens)).numpy() # (batch, sequence, vocab)
10 preds = preds[:,-1, :] #(batch, vocab)
11 if temperature==0:
/opt/conda/lib/python3.7/site-packages/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
1035 with autocast_variable.enable_auto_cast_variables(
1036 self._compute_dtype_object):
-> 1037 outputs = call_fn(inputs, *args, **kwargs)
1038
1039 if self._activity_regularizer:
/tmp/ipykernel_23/4251248884.py in call(self, inputs)
20 # Look at the image
21 for dec_layer in self.decoder_layers:
---> 22 txt = dec_layer(inputs=(image, txt))
23
24 txt = self.output_layer(txt)
/opt/conda/lib/python3.7/site-packages/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
1035 with autocast_variable.enable_auto_cast_variables(
1036 self._compute_dtype_object):
-> 1037 outputs = call_fn(inputs, *args, **kwargs)
1038
1039 if self._activity_regularizer:
/tmp/ipykernel_23/725126540.py in call(self, inputs, training)
16
17 # Text input
---> 18 out_seq = self.self_attention(out_seq)
19
20 out_seq = self.cross_attention(out_seq, in_seq)
/opt/conda/lib/python3.7/site-packages/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
1035 with autocast_variable.enable_auto_cast_variables(
1036 self._compute_dtype_object):
-> 1037 outputs = call_fn(inputs, *args, **kwargs)
1038
1039 if self._activity_regularizer:
/tmp/ipykernel_23/1379568068.py in call(self, x)
8
9 def call(self, x):
---> 10 attn = self.mha(query=x, value=x, use_causal_mask=True)
11 print("mask", attn, "end_mask")
12 x = self.add([x, attn])
/opt/conda/lib/python3.7/site-packages/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
1035 with autocast_variable.enable_auto_cast_variables(
1036 self._compute_dtype_object):
-> 1037 outputs = call_fn(inputs, *args, **kwargs)
1038
1039 if self._activity_regularizer:
TypeError: call() got an unexpected keyword argument 'use_causal_mask'
Code:
tensorflow tutorial for image captioning (instead of mobilenetv3, I am using inceptionV3)
dataset:
filckr8k dataset from kaggle -> https://www.kaggle.com/datasets/adityajn105/flickr8k
The error is generated from multiheadattention of causal self-attention layer
I have tried removing the use_causal_mask kwarg from call method and it seems to work fine
答案1
得分: 1
use_causal_mask
是在Tensorflow版本2.10.0中引入的。
在这个博客中了解更多信息。
请验证您正在使用Tensorflow 2.10.0或更高版本。
英文:
use_causal_mask
was introduced in Tensorflow version 2.10.0.
Read more in this blog
Verify that you are using tensorflow 2.10.0 or above.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论