my code as:
def CrossEntropyLoss(self, logit, target):
n, c, h, w = logit.size()
criterion = nn.CrossEntropyLoss(weight=self.weight, ignore_index=self.ignore_index,
size_average=self.size_average)
if self.cuda:
criterion = criterion.cuda()
target=target.reshape(-1,513,513)
loss = criterion(logit, target.long())
    if self.batch_average:
        loss /= n

    return loss

def training(self, epoch):
train_loss = 0.0
self.model.train()
tbar = tqdm(self.train_loader)
num_img_tr = len(self.train_loader)
for i, sample in enumerate(tbar):
image, target = sample[‘image’], sample[‘label’]
if self.config[‘network’][‘use_cuda’]:
image, target = image.cuda(), target.cuda()
self.scheduler(self.optimizer, i, epoch, self.best_pred)
self.optimizer.zero_grad()
output = self.model(image)
loss = self.criterion(output, target) #
loss.backward()
self.optimizer.step()
train_loss += loss.item()
tbar.set_description(‘Train loss: %.3f’ % (train_loss / (i + 1)))
self.writer.add_scalar(‘train/total_loss_iter’, loss.item(), i + num_img_tr * epoch)
        # Show 10 * 3 inference results each epoch
        if i % (num_img_tr // 10) == 0:
            global_step = i + num_img_tr * epoch
            self.summary.visualize_image(self.writer, self.config['dataset']['dataset_name'], image, target, output, global_step)

    self.writer.add_scalar('train/total_loss_epoch', train_loss, epoch)
    print('[Epoch: %d, numImages: %5d]' % (epoch, i * self.config['training']['batch_size'] + image.data.shape[0]))
    print('Loss: %.3f' % train_loss)

    #save last checkpoint
    self.saver.save_checkpoint({
        'epoch': epoch + 1,

‘state_dict’: self.model.module.state_dict(),
        'state_dict': self.model.state_dict(),
        'optimizer': self.optimizer.state_dict(),
        'best_pred': self.best_pred,
    }, is_best = False, filename='checkpoint_last.pth.tar')

    #if training on a subset reshuffle the data 
    if self.config['training']['train_on_subset']['enabled']:
        self.train_loader.dataset.shuffle_dataset()