Lazy Torch requirement
import parlai.core.build_data as build_data
-import torch
-from torch.autograd import Variable
-import torchvision
-import torchvision.transforms as transforms
-import torch.nn as nn
-
import os
import copy
import numpy as np
@@ -34,6 +28,15 @@ class ImageLoader():
def init_cnn(self):
"""Lazy initialization of preprocessor model in case we don't need any image preprocessing."""
+ try:
+ import torch
+ except ModuleNotFoundError:
+ raise ModuleNotFoundError('Need to install pytorch: go to pytorch.org')
+ from torch.autograd import Variable
+ import torchvision
+ import torchvision.transforms as transforms
+ import torch.nn as nn
+
opt = self.opt
self.image_size = opt['image_size']
self.crop_size = opt['image_cropsize']
@@ -153,6 +156,3 @@ class ImageLoader():
return self.extract(Image.open(path).convert('RGB'), new_path)
else:
return np.load(new_path)
-
-
-
