leeyeehoo / CSRNet-pytorch

CSRNet: Dilated Convolutional Neural Networks for Understanding the Highly Congested Scenes
656 stars 259 forks source link

Loading trained model #98

Closed Chrisz7709 closed 1 year ago

Chrisz7709 commented 1 year ago

Hello, I am trying to load the checkpoint file created from the train.py script. It continually gets errors of not having permission. I have checked all permissions and I cannot see where the permission would not be granted. Here is the error to be more specific (csrnet_env) PS C:\Users\Chris\CSRNet-pytorch> C:/desktop/Python38/python.exe "C:\Users\Chris\CSRNet-pytorch\unpickle.py" C:\desktop\Python38\lib\site-packages\torchvision\models_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead. warnings.warn( C:\desktop\Python38\lib\site-packages\torchvision\models_utils.py:223: UserWarning: Arguments other than a weight enum or None for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing weights=VGG16_Weights.IMAGENET1K_V1. You can also use weights=VGG16_Weights.DEFAULT to get the most up-to-date weights. warnings.warn(msg) Traceback (most recent call last): File "C:\Users\Chris\CSRNet-pytorch\unpickle.py", line 19, in with open(path, 'rb') as f: PermissionError: [Errno 13] Permission denied: 'C:\Users\Chris\CSRNet-pytorch\1checkpoint.pth' This is the code I am running import os import torch from make_model import CSRNet import io

def custom_persistent_load(saved_id): typename = saved_id[0] data = saved_id[1]

if typename == 'torch.cuda.FloatTensor':
    storage = torch.FloatStorage.from_buffer(data)
    return storage
else:
    raise RuntimeError(f"Unknown typename '{typename}' in persistent_load")

path = r"C:\Users\Chris\CSRNet-pytorch\1checkpoint.pth" os.chmod(path, 0o777)

with open(path, 'rb') as f: checkpoint_data = f.read()

buffer = io.BytesIO(checkpoint_data) checkpoint = torch.load(buffer, map_location=torch.device('cpu'), pickle_module=pickle)

from make_model import CSRNet

model = CSRNet(load_weights=False) model.load_state_dict(checkpoint['state_dict']) print("unpickled:") print(model)

A professor told me it is likely related to torch.load.

Is there any way someone got their checkpoint to load?

Chrisz7709 commented 1 year ago

Also I am using torch 2.0 and cuda 11.8

Chrisz7709 commented 1 year ago

I found out the issue. I had the data set unzipped. The folder should remain zipped when loading the data.