Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

device=torch.device('cpu') #47

Open
lcxsnow opened this issue Jun 28, 2023 · 1 comment
Open

device=torch.device('cpu') #47

lcxsnow opened this issue Jun 28, 2023 · 1 comment

Comments

@lcxsnow
Copy link

lcxsnow commented Jun 28, 2023

/home/m11113013/.local/lib/python3.8/site-packages/scipy/init.py:138: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.24.3)
warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion} is required for this version of "
compute FID between two folders
Found 8091 images in the folder /dataset/flickr/images/
FID : 0%| | 0/506 [00:00<?, ?it/s]
Traceback (most recent call last):
File "/home/m11113013/ProjectCode/MasterProject4/model/metric.py", line 12, in
score = calculate_fid(p1, p1)
File "/home/m11113013/ProjectCode/MasterProject4/model/metric.py", line 5, in calculate_fid
return fid.compute_fid(x_dir, y_dir, mode='clean', num_workers=0, batch_size=16, device=torch.device("cpu"))
File "/home/m11113013/miniconda3/envs/pytorch/lib/python3.8/site-packages/cleanfid/fid.py", line 478, in compute_fid
score = compare_folders(fdir1, fdir2, feat_model,
File "/home/m11113013/miniconda3/envs/pytorch/lib/python3.8/site-packages/cleanfid/fid.py", line 269, in compare_folders
np_feats1 = get_folder_features(fdir1, feat_model, num_workers=num_workers,
File "/home/m11113013/miniconda3/envs/pytorch/lib/python3.8/site-packages/cleanfid/fid.py", line 147, in get_folder_features
np_feats = get_files_features(files, model, num_workers=num_workers,
File "/home/m11113013/miniconda3/envs/pytorch/lib/python3.8/site-packages/cleanfid/fid.py", line 119, in get_files_features
l_feats.append(get_batch_features(batch, model, device))
File "/home/m11113013/miniconda3/envs/pytorch/lib/python3.8/site-packages/cleanfid/fid.py", line 88, in get_batch_features
feat = model(batch.to(device))
File "/home/m11113013/miniconda3/envs/pytorch/lib/python3.8/site-packages/cleanfid/features.py", line 25, in model_fn
def model_fn(x): return model(x)
File "/home/m11113013/miniconda3/envs/pytorch/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home/m11113013/miniconda3/envs/pytorch/lib/python3.8/site-packages/torch/nn/parallel/data_parallel.py", line 154, in forward
raise RuntimeError("module must have its parameters and buffers "
RuntimeError: module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cpu

import torch
from cleanfid import fid

def calculate_fid(x_dir, y_dir):
return fid.compute_fid(x_dir, y_dir, mode='clean', num_workers=0, batch_size=16, device=torch.device("cpu"))

if name == "main":
p1 = '/dataset/flickr/images/'
score = calculate_fid(p1, p1)
print(score)

python version: 3.8.16
pytorch version: 1.12.1
cuda version: 11.3

@bertinma
Copy link

You have to compute it using cuda, so replace device=torch.device('cpu') by device=torch.device('cuda') or remove it as the device argument is set to "cuda" by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants