Skip to content

Requirements for inference mode and path to weights.pt #4

@kkedich

Description

@kkedich

It seems that torchvision needs to be included in the requirements list. I tried to create a conda environment with just pytorch and python3.7, but that didn't work.

Conda environment created with:

    conda create --name dists python=3.7
    pip install -r requirements.txt

Error:

Traceback (most recent call last):
  File "DISTS_pt.py", line 8, in <module>
    from torchvision import models, transforms
ModuleNotFoundError: No module named 'torchvision'

Adding the torchvision to the requirements list fix this.
Additionally, when using the conda env, the path to the weights file DISTS_pytorch/weights.pt seems to point to an incorrect path. The sys.prefix points to the env directory (example: /home/karinabogdan/anaconda3/envs/dists/) and not the weights file in DISTS_pytorch/

python DISTS_pt.py --ref ../example_input/12_enh.jpg --dist ../example_input/12_raw.jpg
Traceback (most recent call last):
  File "DISTS_pt.py", line 134, in <module>
    model = DISTS().to(device)
  File "DISTS_pt.py", line 63, in __init__
    weights = torch.load(os.path.join(sys.prefix, 'weights.pt'))
  File "/home/karinabogdan/anaconda3/envs/dists/lib/python3.7/site-packages/torch/serialization.py", line 581, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "/home/karinabogdan/anaconda3/envs/dists/lib/python3.7/site-packages/torch/serialization.py", line 230, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/home/karinabogdan/anaconda3/envs/dists/lib/python3.7/site-packages/torch/serialization.py", line 211, in __init__
    super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: '/home/karinabogdan/anaconda3/envs/dists/weights.pt'

I fixed that by changing the line:

weights = torch.load(os.path.join(sys.prefix, 'weights.pt'))

to

from pathlib import Path, PurePosixPath
weights = torch.load(str(PurePosixPath(Path.cwd()).joinpath('weights.pt')))

but I am not sure if this is the best way to handle this.

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