How to Implement the FaceDetection-DSFD Demo on Windows

Original article was published by The Altruist on Deep Learning on Medium


RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=’cpu’ to map your storages to the CPU.

This step only applies to those of us who don’t yet possess a gpu — cpu only.

Next, we’ll change the default value of “map_location” in the following file:

  1. venv/lib/python3.6/site-packages/torch/serialization.py — line 300
serialization.py:
def load(f, map_location="cpu", pickle_module=pickle):

...

AssertionError: Torch not compiled with CUDA enabled

This step only applies to those of us who don’t yet possess a gpu — cpu only.

Next, we’ll comment-out “cuda()” in the following files:

  1. demo.py — line 69 & 70
  2. demo.py — line 172
  3. widerface_val.py — line 232
demo.py:
def infer(net , img , transform , thresh , cuda , shrink):
if shrink != 1:
img = cv2.resize(img, None, None, fx=shrink, fy=shrink, interpolation=cv2.INTER_LINEAR)
x = torch.from_numpy(transform(img)[0]).permute(2, 0, 1)
with torch.no_grad():
x = Variable(x.unsqueeze(0))
#if cuda:
# x = x.cuda()
...
demo.py:
def test_oneimage():
torch.set_grad_enabled(False)
# load net
cfg = widerface_640
num_classes = len(WIDERFace_CLASSES) + 1 # +1 background
net = build_ssd('test', cfg['min_dim'], num_classes) # initialize SSD
net.load_state_dict(torch.load(args.trained_model))
#net.cuda()
...
widerface_val.py:
# load net
cfg = widerface_640
num_classes = len(WIDERFace_CLASSES) + 1 # +1 background
net = build_ssd('test', cfg['min_dim'], num_classes) # initialize SSD
net.load_state_dict(torch.load(args.trained_model))
#net.cuda()
...