Python 开始\u epoch=全局\u步长//Numatch ZeroDivision错误:整数除法或模零除法

Python 开始\u epoch=全局\u步长//Numatch ZeroDivision错误:整数除法或模零除法,python,tensorflow2.0,Python,Tensorflow2.0,我不知道这个错误的原因,所以我在网上寻求帮助。请原谅我的原始代码是如此粗糙,因为我只是一个初学者 在调试过程中,我在这行上遇到一个错误: start_epoch = global_step // numBatch 错误: ZeroDivisionError: integer division or modulo by zero 这是我的密码: def train(self, train_low_data, train_high_data, eval_low_data, batch_size,

我不知道这个错误的原因,所以我在网上寻求帮助。请原谅我的原始代码是如此粗糙,因为我只是一个初学者

在调试过程中,我在这行上遇到一个错误:

start_epoch = global_step // numBatch
错误:

ZeroDivisionError: integer division or modulo by zero
这是我的密码:

def train(self, train_low_data, train_high_data, eval_low_data, batch_size, patch_size, epoch, lr, sample_dir, ckpt_dir, eval_every_epoch, train_phase):
    assert len(train_low_data) == len(train_high_data)
    numBatch = len(train_low_data) // int(batch_size)

    # load pretrained model
    if train_phase == "Decom":
        train_op = self.train_op_Decom
        train_loss = self.loss_Decom
        saver = self.saver_Decom
    elif train_phase == "Relight":
        train_op = self.train_op_Relight
        train_loss = self.loss_Relight
        saver = self.saver_Relight

    load_model_status, global_step = self.load(saver, ckpt_dir)
    if load_model_status:
        iter_num = global_step
        start_epoch = global_step // numBatch
        start_step = global_step % numBatch
        print("[*] Model restore success!")
    else:
        iter_num = 0
        start_epoch = 0
        start_step = 0
        print("[*] Not find pretrained model!")

   print("[*] Start training for phase %s, with start epoch %d start iter %d : " % (train_phase, start_epoch, iter_num))

这很可能是因为你要除以零

Nubatch为零,这意味着train_low_数据可能为零

在运行该函数之前,您应该验证这一点,因为如果您没有任何训练内容,则该函数将毫无意义。我在函数的开头添加了另一个断言:

def train(self, train_low_data, train_high_data, eval_low_data, batch_size, patch_size, epoch, lr, sample_dir, ckpt_dir, eval_every_epoch, train_phase):
    assert len(train_low_data) > 0
    assert len(train_low_data) == len(train_high_data)
    numBatch = len(train_low_data) // int(batch_size)

    # load pretrained model
    if train_phase == "Decom":
        train_op = self.train_op_Decom
        train_loss = self.loss_Decom
        saver = self.saver_Decom
    elif train_phase == "Relight":
        train_op = self.train_op_Relight
        train_loss = self.loss_Relight
        saver = self.saver_Relight

    load_model_status, global_step = self.load(saver, ckpt_dir)
    if load_model_status:
        iter_num = global_step
        start_epoch = global_step // numBatch
        start_step = global_step % numBatch
        print("[*] Model restore success!")
    else:
        iter_num = 0
        start_epoch = 0
        start_step = 0
        print("[*] Not find pretrained model!")

print("[*] Start training for phase %s, with start epoch %d start iter %d : " % (train_phase, start_epoch, iter_num))
能否在“加载预训练模型”之前添加线条打印(Nubatch)。检查numBatch的值。