av-savchenko/face-emotion-recognition

Python package excess dependency

ioctl-user opened this issue · 11 comments

Hello!

It seems, python package has excess dependency timm. This module is imported, but not used.

Hello! Thanks for this question. My PyTorch models are modifications of EfficientNet models from timm repository. They use several internal classes of this repo. I tested them with different architectures and operating systems and torch.load() fails sometimes if timm has not been installed. That's why I decided to externally show this the dependence. But you are correct, import timm is not necessary in the main file of my package. I will remove it in several days when I return back to my PC.

I removed import of timm in facial_emotions.py. But I'm not sure that it is appropriate to remove timm from requirements for the reasons from my previous comment

It works without that line in facial_emotions.py and doesn't works without timm package installed.

Seems, current situation is optimal.

Torch package does not requires timm.
It seems, models itself requires it. For example, if you rename model enet_b0_8_best_afew.pt to zip file and unpack it, there will be file data.pkl, that contains a lot of timm references.

I have assumption, that enet models depends on standard timm models.

If so, is it possible to repack them to always include needed models?

As I said earlier, it uses some classes from timm, so that they require it to be installed. Do you have a guess how to pack the classes inside a package? I am not sure that I could find the solution now. One of the possible options is to convert ptl models to ONNX, they won't require both timm and pytorch. I tested such a solution, the inference is much faster on CPU of a laptop

Unfortunately I am not familiar with pytorch and timm, so, I cannot guess about packing.

Actually, problem appears after building my app with the Nuitka compiler for Windows distribution. Timm uses JIT, that can be compiled, but app doesn't working.

Could you give advice, how to repack and use enet models to ONNX? Or, may be, will you consider implement it in the upstream to reduce overall weight of dependencies?

Timm is much smaller when compared to pytorch, but you're correct, it will be great to provide an additional code with running the ONNX model. But I need a couple of days before I can return back to this task

For the information.

Here is an example of the NN project using ONNX data files with OpenCV library only: https://github.com/Star-Clouds/CenterFace/tree/master/prj-python

I added hsemotion_onnx library and examples of its usage. I uses onnxruntime package instead of opencv because I have previously implemented something similar with onnxruntime and performance on CPU was really good. Please, let me know if it works for you.

It works fine!

The only note: please add onnx to the onnx-based package dependence list, because onnxruntime installed with pip doesn't requires onnx itself.

Thanks!

Done, thanks for you note and testing the package