phoenixtreesky7 / CFEN-ViT-Dehazing

17 stars 3 forks source link

ECLoss and TVLoss package can not find and how to install these packages #3

Open 17328-wu opened 2 years ago

17328-wu commented 2 years ago

Thanks for your sharing! When I execute the script test.py ,the following error occurred: ModuleNotFoundError: No module named 'ECLoss'

However, I can't find the package using the pip install command and on the website How can I solve this problem? Looking forward to your reply, thanks !

17328-wu commented 2 years ago

After I solve the above problems,the following error occurred:

loading the model from ./checkpoints\iid_hlgvit_crs_gd4_cfs_v3_ohaze\20_net_G.pth Traceback (most recent call last): File "test.py", line 28, in model.setup(opt) File "D:\py-local-pro\【paper】CFEN-ViT-Dehazing\models\base_model.py", line 41, in setup self.load_networks(opt.which_epoch) File "D:\py-local-pro\【paper】CFEN-ViT-Dehazing\models\base_model.py", line 130, in load_networks self.patch_instance_norm_state_dict(state_dict, net, key.split('.')) File "D:\py-local-pro\【paper】CFEN-ViT-Dehazing\models\base_model.py", line 111, in patch_instance_norm_state_dict self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) File "D:\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1177, in getattr raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'ipt' object has no attribute 'localvit_decoder_03r'

This is very confusing to me.Do you know the cause of the error? Looking forward to your reply,thanks!

chetanpandey1266 commented 2 years ago

ModuleNotFoundError: No module named 'ECLoss'

How were you able to resolve this error??

17328-wu commented 2 years ago

ModuleNotFoundError: No module named 'ECLoss'

How were you able to resolve this error??

I found it on the https://github.com/HUSTSYJ/DA_dahazing

17328-wu commented 2 years ago

How were you able to resolve this error?? When I run the test.py file following the instructions given by the author, I get some errors:

AttributeError: 'ipt' object has no attribute 'localvit_decoder_03r'

Do you have similar cases?

chetanpandey1266 commented 2 years ago

Do you have similar cases?

Yeah I am facing the same issue. I checked the files and found that the main problem lies in the following file model/base_model.py. I think, the following function must be edited in this file.

def load_networks(self, which_epoch):
    for name in self.model_names:
        if isinstance(name, str):
            load_filename = '%s_net_%s.pth' % (which_epoch, name)
            load_path = os.path.join(self.save_dir, load_filename)

            net = getattr(self, 'net' + name)
            if isinstance(net, torch.nn.DataParallel):
                net = net.module
                #net = torch.nn.DataParallel(net, device_ids=range(torch.cuda.device_count()))
            print('loading the model from %s' % load_path)
            # if you are using PyTorch newer than 0.4 (e.g., built from
            # GitHub source), you can remove str() on self.device
            state_dict = torch.load(load_path, map_location=str(self.device))
            # patch InstanceNorm checkpoints prior to 0.4
            for key in list(state_dict.keys()):  # need to copy keys here because we mutate in loop
                self.__patch_instance_norm_state_dict(state_dict, net, key.split('.'))
            net.load_state_dict(state_dict)

In the above function they are using net = getattr(self, 'net'+name) to get the model and state_dict = .... to get the state_dicts. I printed both and noticed that localvit_decoder_03r is present in state_dict but not in net. And this is the reason for that error.

This is what I found. If you are able to resolve this then please share the solution here.

17328-wu commented 2 years ago

Thanks for you reply. Yes, I found that too. But don't know how to solve the problem.

SuperFat219 commented 1 year ago

Thanks for you reply. Yes, I found that too. But don't know how to solve the problem.

On the one hand, you need to adjust the selected model when loading the model parameters, for example, using dec-vit model, and then loading the corresponding parameters. This step needs to adjust the code to load the model as needed. In addition, some parameters in base_option.py also need to be adjusted by yourself.