tensorflow TypeError:call()获得意外的关键字参数“use_causal_mask”--->在flickr 8 k/flickr 30 k数据集上获得此错误

fdbelqdn  于 2023-02-13  发布在  其他
关注(0)|答案(1)|浏览(117)

错误

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'

代码:

图像字幕的tensorflow教程(而不是mobilenetv 3,我正在使用inceptionv 3)

数据集:

从kaggle -〉https://www.kaggle.com/datasets/adityajn105/flickr8k填充ckr 8 k数据集
这个错误是由因果自我关注层的multiheadattention生成的我尝试过从call方法中删除use_causal_mask kwarg,看起来效果不错

ccgok5k5

ccgok5k51#

在Tensorflow版本2.10.0中引入了use_causal_mask。[https://blog.tensorflow.org/2022/09/whats-new-in-tensorflow-210.html]
验证您使用的是tensorflow 2.10.0或更高版本。

相关问题