在学习tensorflow2实现YOLO3时遇到在非eager模式下训练报错问题

在训练您的模型(运行train.py时)将eager模式设置为True时,训练正常没有报错。但是选择为非eager模式是,设置为False时报错了
提示是进入这步时报错:

img

问题相关代码,请勿粘贴截图
运行结果及报错内容

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>.

我的解答思路和尝试过的方法

感觉是loss损失函数有问题,但关于tensorflow2定义自己的损失函数一致不太明白,如何写自己的损失函数,是否有严格格式规定(比如形参是true,和predict两个),并且要和model.fit中传入的训练数据要对应。

我想要达到的结果

解决问题,理解如何在tensorflow2中灵活定义自己的损失函数