miemie2013 / Keras-YOLOv4

yolov4 42.0% mAP.ppyolo 45.1% mAP.
446 stars 127 forks source link

ValueError: slice index -1 of dimension 0 out of bounds. 错误 #23

Closed WaltPeter closed 4 years ago

WaltPeter commented 4 years ago

在运行train.py时,模型能成功导入,但是yolo_loss处则出现报错,如下:

Traceback (most recent call last): File "train.py", line 370, in model.compile(loss={"yolo_loss": lambda y_true, y_pred: y_pred}, optimizer=keras.optimizers.Adam(lr=cfg.lr)) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper result = method(self, *args, *kwargs) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 446, in compile self._compile_weights_loss_and_weighted_metrics() File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper result = method(self, args, **kwargs) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 1592, in _compile_weights_loss_and_weighted_metrics self.total_loss = self._prepare_total_loss(masks) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 1652, in _prepare_total_loss per_sample_losses = loss_fn.call(y_true, y_pred) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/keras/losses.py", line 220, in call y_pred, y_true) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/ops/losses/util.py", line 79, in squeeze_or_expand_dimensions is_last_dim_1 = math_ops.equal(1, array_ops.shape(y_pred)[-1]) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/ops/array_ops.py", line 898, in _slice_helper name=name) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/ops/array_ops.py", line 1064, in strided_slice shrink_axis_mask=shrink_axis_mask) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 9535, in strided_slice shrink_axis_mask=shrink_axis_mask, name=name) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/framework/op_def_library.py", line 742, in _apply_op_helper attrs=attr_protos, op_def=op_def) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 3322, in _create_op_internal op_def=op_def) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 1786, in init control_input_ops) File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 1622, in _create_c_op raise ValueError(str(e)) ValueError: slice index -1 of dimension 0 out of bounds. for 'loss/yolo_loss_loss/strided_slice' (op: 'StridedSlice') with input shapes: [0], [1], [1], [1] and with computed input tensors: input[1] = <-1>, input[2] = <0>, input[3] = <1>.

使用的是自制数据集。另外,keras模块全部是使用tensorflow内的keras submodule。百度了下还是没法子。谢谢

WaltPeter commented 4 years ago

原因是tf上的keras submodule是和本来的keras模块有一定的不兼容性。