bert4keras
bert4keras copied to clipboard
TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
提问时请尽可能提供如下信息:
基本信息
- 你使用的操作系统: win10
- 你使用的Python版本: 3.6
- 你使用的Tensorflow版本: 2.0.1
- 你使用的Keras版本: 2.3.1
- 你使用的bert4keras版本: 0.10.1
- 你使用纯keras还是tf.keras: tf.keras
- 你加载的预训练模型: roberta
核心代码
https://github.com/bojone/bert4keras/blob/41cff076fb2b0f4856b752bacebed607f02668ce/examples/task_sentiment_albert.py
输出信息
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\framework\tensor_shape.py in __init__(self, value)
191 raise TypeError("Cannot convert %s to Dimension" % value)
192 else:
--> 193 self._value = int(value)
194 if (not isinstance(value, compat.bytes_or_text_types) and
195 self._value != value):
TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
自我尝试
我使用tf2的keras(加上os.environ['TF_KERAS'] = '1')时就回报一下错误 但是当我使用的是keras,而不是tf.keras就没有这个错误
可以发一下完整的错误信息吗?我需要知道在bert4keras的哪一行出现错误。
可以发一下完整的错误信息吗?我需要知道在bert4keras的哪一行出现错误。
TypeError Traceback (most recent call last)
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs) 726 max_queue_size=max_queue_size, 727 workers=workers, --> 728 use_multiprocessing=use_multiprocessing) 729 730 def evaluate(self,
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, **kwargs) 222 validation_data=validation_data, 223 validation_steps=validation_steps, --> 224 distribution_strategy=strategy) 225 226 total_samples = _get_total_number_of_samples(training_data_adapter)
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in _process_training_inputs(model, x, y, batch_size, epochs, sample_weights, class_weights, steps_per_epoch, validation_split, validation_data, validation_steps, shuffle, distribution_strategy, max_queue_size, workers, use_multiprocessing) 545 max_queue_size=max_queue_size, 546 workers=workers, --> 547 use_multiprocessing=use_multiprocessing) 548 val_adapter = None 549 if validation_data:
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in _process_inputs(model, x, y, batch_size, epochs, sample_weights, class_weights, shuffle, steps, distribution_strategy, max_queue_size, workers, use_multiprocessing) 604 max_queue_size=max_queue_size, 605 workers=workers, --> 606 use_multiprocessing=use_multiprocessing) 607 # As a fallback for the data type that does not work with 608 # _standardize_user_data, use the _prepare_model_with_inputs.
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\keras\engine\data_adapter.py in init(self, x, y, sample_weights, **kwargs) 564 self._first_batch_size = int(nest.flatten(peek)[0].shape[0]) 565 self._dataset = dataset_ops.DatasetV2.from_generator( --> 566 reassemble, nested_dtypes, output_shapes=nested_shape) 567 568 def get_dataset(self):
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\data\ops\dataset_ops.py in from_generator(generator, output_types, output_shapes, args) 538 else: 539 output_shapes = nest.map_structure_up_to( --> 540 output_types, tensor_shape.as_shape, output_shapes) 541 if args is None: 542 args = ()
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\data\util\nest.py in map_structure_up_to(shallow_tree, func, *inputs) 469 for input_tree in inputs] 470 --> 471 results = [func(*tensors) for tensors in zip(*all_flattened_up_to)] 472 return pack_sequence_as(structure=shallow_tree, flat_sequence=results)
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\data\util\nest.py in
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\framework\tensor_shape.py in as_shape(shape) 1214 return shape 1215 else: -> 1216 return TensorShape(shape) 1217 1218
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\framework\tensor_shape.py in init(self, dims) 774 else: 775 # Got a list of dimensions --> 776 self._dims = [as_dimension(d) for d in dims_iter] 777 778 @property
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\framework\tensor_shape.py in
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\framework\tensor_shape.py in as_dimension(value) 716 return value 717 else: --> 718 return Dimension(value) 719 720
C:\ProgramData\Anaconda3\envs\dp_gpu_tf2\lib\site-packages\tensorflow_core\python\framework\tensor_shape.py in init(self, value) 191 raise TypeError("Cannot convert %s to Dimension" % value) 192 else: --> 193 self._value = int(value) 194 if (not isinstance(value, compat.bytes_or_text_types) and 195 self._value != value):
TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
当使用keras的时候就不会出现,但是加入os.environ['TF_KERAS'] = '1'
就有了这个错误
当使用keras的时候就不会出现,但是加入
os.environ['TF_KERAS'] = '1'
就有了这个错误
同,今天遇到了这个错误。但是去掉这句话就有新的错误:
AttributeError: 'tuple' object has no attribute 'layer'