Skip to content

How to solve issues during inference code #7

Description

@intMinsu

When you run inference like repo says:
python ./src/main.py validate --config ./configs/val.yaml --trainer.logger null
you will face many errors.
This issue will guide how to solve these.

  1. Error in "python src/main.py fit --config ./configs/train_stage1.yaml" #6 error: Parser key "model"
    Reason: possibly related to torchmetrics version mismatch.
    Fix: change the lines importing FID and LPIPS in UniRestore/src/core/base/eval_image_restoration.py and UniRestore/src/core/base/eval_multi_task.py
  • Original code :
from torchmetrics.image import FrechetInceptionDistance as FID
from torchmetrics.image import LearnedPerceptualImagePatchSimilarity as LPIPS
  • Fixed code :
from torchmetrics.image.fid import FrechetInceptionDistance as FID
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity as LPIPS
  1. Errors Encountered During Inference #4 ImportError: cannot import name 'TaskEditorV1c' from 'modules.diffuie.taskeditor'
    Reason: wrong class name.
    Fix: change class name in UniRestore/src/modules/diffuie/autoencoder.py
  • Original Code :
if self.tedit_type == "TFA":
    from .taskeditor import TaskEditorV1c as TaskEditor
  • Fixed Code :
if self.tedit_type == "TFA":
    from .taskeditor import TaskFeatureAdapter as TaskEditor
  1. Errors Encountered During Inference #4 TypeError: SkipConnectedAutoEncoder.forward() missing 1 required positional argument: 'task'
    Reason: calflops.calculate_flops cannot handle stable diffusion VAE forward naively
    Fix: just comment out calculate_flops part in UniRestore/src/modules/diffuie/unifie.py
  • Fixed Code :
# flops, macs, params = calculate_flops(model = self.ae,
#                                       input_shape=input_shape,
#                                       output_as_string=True,
#                                       output_precision=4)
# print("UniRestore.AEs FLOPs:%s   MACs:%s   Params:%s \n" %(flops, macs, params))
# raise TypeError

# for name, param in self.ae.vae.decoder.named_parameters():
#     param.register_hook(lambda grad, name=name: print(f"Gradient computed for: {name}"))

Hope it helps

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions