AttributeError: 'NoneType' object has no attribute 'dtype'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_23207/4182898696.py in <module>
45 monitor='loss') # 由于
46
---> 47 history = model.fit(x_train, y_train, batch_size=32, epochs=100, callbacks=[cp_callback])
48
49 model.summary()
/home/software/anaconda3/envs/tf115/lib/python3.7/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)
725 max_queue_size=max_queue_size,
726 workers=workers,
--> 727 use_multiprocessing=use_multiprocessing)
728
729 def evaluate(self,
/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_arrays.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)
641 steps=steps_per_epoch,
642 validation_split=validation_split,
--> 643 shuffle=shuffle)
644
645 if validation_data:
/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, batch_size, check_steps, steps_name, steps, validation_split, shuffle, extract_tensors_from_dataset)
2430 is_compile_called = False
2431 if not self._is_compiled and self.optimizer:
-> 2432 self._compile_from_inputs(all_inputs, y_input, x, y)
2433 is_compile_called = True
2434
/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py in _compile_from_inputs(self, all_inputs, target, orig_inputs, orig_target)
2665 sample_weight_mode=self.sample_weight_mode,
2666 run_eagerly=self.run_eagerly,
-> 2667 experimental_run_tf_function=self._experimental_run_tf_function)
2668
2669 # TODO(omalleyt): Consider changing to a more descriptive function name.
/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/tensorflow_core/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
455 self._self_setattr_tracking = False # pylint: disable=protected-access
456 try:
--> 457 result = method(self, *args, **kwargs)
458 finally:
459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py in compile(self, optimizer, loss, metrics, loss_weights, sample_weight_mode, weighted_metrics, target_tensors, distribute, **kwargs)
341 self.loss_functions, target_tensors):
342 endpoint = _TrainingEndpoint(o, n, l)
--> 343 endpoint.create_training_target(t, run_eagerly=self.run_eagerly)
344 self._training_endpoints.append(endpoint)
345
/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py in create_training_target(self, target, run_eagerly)
3060 if target is None:
3061 target_dtype = losses.LABEL_DTYPES_FOR_LOSSES.get(
-> 3062 self.loss_fn, K.dtype(self.output))
3063
3064 target = K.placeholder(
/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/tensorflow_core/python/keras/backend.py in dtype(x)
1241 ```
1242 """
-> 1243 return x.dtype.base_dtype.name
1244
1245
AttributeError: 'NoneType' object has no attribute 'dtype'
AttributeError:“ NoneType”对象没有属性“ dtype”
可能是Numpy和TensorFlow兼容性问题。
目前使用的是TensorFlow2.1版本,于是将Numpy版本修改为1.18.5,发现问题得到解决