I modified the method as follows:
def forward(self, imagePath):

Now I get this error:
" torch.jit.frontend.UnsupportedNodeError: DictComp aren’t supported"
  (base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ python3 
  ./getFaceEmbedding.py 
  Traceback (most recent call last):
    File "./getFaceEmbedding.py", line 127, in <module>
      sm = torch.jit.script(my_module)
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/__init__.py", line 1255, in 
  script
      return torch.jit._recursive.recursive_script(obj)
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 534, in 
  recursive_script
      return create_script_module(nn_module, infer_methods_to_compile(nn_module))
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 493, in 
  infer_methods_to_compile
      stubs.append(make_stub_from_method(nn_module, method))
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 40, in 
  make_stub_from_method
      return make_stub(func)
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 33, in 
  make_stub
      ast = torch.jit.get_jit_def(func, self_name="RecursiveScriptModule")
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 171, in 
  get_jit_def
      return build_def(ctx, py_ast.body[0], type_line, self_name)
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 212, in 
  build_def
      build_stmts(ctx, body))
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 127, in 
  build_stmts
      stmts = [build_stmt(ctx, s) for s in stmts]
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 127, in 
  <listcomp>
      stmts = [build_stmt(ctx, s) for s in stmts]
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 187, in 
  __call__
      return method(ctx, node)
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 289, in 
  build_Assign
      rhs = build_expr(ctx, stmt.value)
    File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 186, in 
  __call__
      raise UnsupportedNodeError(ctx, node)
  torch.jit.frontend.UnsupportedNodeError: DictComp aren't supported:
    File "./getFaceEmbedding.py", line 79
          dataset = datasets.ImageFolder(imagePath)
          dataset.idx_to_class = {i:c for c, i in dataset.class_to_idx.items()}
                                 ~ <--- HERE
          loader = DataLoader(dataset, collate_fn=collate_fn, num_workers=workers)

I read here: https://pytorch.org/tutorials/advanced/cpp_export.html 2
that “If you need to exclude some methods in your nn.Module because they use Python features that TorchScript doesn’t support yet, you could annotate those with @torch.jit.ignore”
But I guess that excluding the dictionary comprehension from the serialization, will interfere with the method’s functionality.
What would you suggest me to do?