AttributeError: module 'torch' has no attribute 'device'

%load_ext autoreload
%autoreload 2

import os, json, argparse, torch, sys
import numpy as np
from tqdm import tqdm
from glob import glob
import torch.nn.functional as F
from multiprocessing import Pool, cpu_count
sys.path.append("…/")

from utils import image
from utils.MobileNetV2_pretrained_imagenet import MobileNetV2
from utils.data import NumpyImageLoader
from utils.metrics import BinaryClassificationMetrics

Print parameters

params = {}
params[“channel”] = “YCbCr”
params[“threshold”] = 0.80
params[“test_subset”] = 5

params[“patch_test_au_dir”] = “…/backup/MBN2-pre-YCbCr/test/au”
params[“patch_test_tp_dir”] = “…/backup/MBN2-pre-YCbCr/test/tp”

params[“training_log_dir”] = “…/backup/MBN2-pre-YCbCr/checkpoints/”
MODEL_FILE = os.path.join(params[“training_log_dir”], “model.ckpt”)
DEVICE = torch.device(‘cuda’ if torch.cuda.is_available() else ‘cpu’)

params[“au_subsets_file”] = “…/dataset/au_subsets.json”
params[“tp_subsets_file”] = “…/dataset/tp_subsets.json”

params[“casia2_au”] = “/media/antiaegis/storing/datasets/CASIA2/Au”
params[“casia2_tp”] = “/media/antiaegis/storing/datasets/CASIA2/Tp”

Could you check your PyTorch version (print(torch.__version__))?
I think torch.device was introduced in 0.4.
You can find the install instructions for the current releast (1.1) here.

1 Like

PyTorch version is 0.3.1, i think that’s the problem, thanks