Pytorch rename labels of a trained model

I have a trained model. During training there was some problem with string characters. So i converted my labels into numbers like:

red : 0

blue: 1

green: 2

Now is it possible to rename my label back to actual label names.
Hours of training. Would be helpful if anyone has an idea.

Train and validate the model

for epoch in range(1, epoch_num + 1):
    loss_train, acc_train = train(train_loader, model, criterion, optimizer, epoch)
    loss_val, acc_val = validate(val_loader, model, criterion, epoch)

Test Single Image:

def eval_image(file_path):
    model = torch.load(file_path)
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
    X ='red.jpeg')
    test_transforms = transforms.Compose([transforms.ToTensor()])
    image_tensor = test_transforms(X).float()
    image_tensor = image_tensor.unsqueeze_(0)
    input = Variable(image_tensor)
    input =
    output = model(input)
    index =

Once the training is done, The evaluation script cannot be made generic. I will have to pass following code

idx_to_class = {
        0: "red",
        1: "blue",
        2: "green",
    class_name = idx_to_class[index]

But I do not want to pass the above code. As my evaluation script needs to generic.

Could you explain a bit more what “generic” means in this case and what is not working for you using this mapping?