Converting OpenPose for Wolfram Language

Allen-san,

I have attached my notebook to the post. It takes about one and a half minutes in my environment. Please make sure.

Your problem may be a problem with indentation in ExternalEvaluate.

I hope this will help.

Thank you Sir!

ExternalEvaluate [ ] has an issue with Python Numpy version so little odd thingy like that.

Hi All,

I tried to test out this model, and it failed all over the place :(:frowning: I am wondering if there is a compatibility issue, if links have broken, or something else. To get it to run at all, I first had to make a few changes:

  1. “Dropbox
    dl=0” points to pose_model.pth, not pose_model_scratch.pth, so I changed the filename in the python ExternalEvaluate[] command sequence to “pose_model.pth” – is that the wrong model?!

  2. I had to register my anaconda 4.8.3 install of python 2.7.16 with mathematica after installing pyzmq; that’s my python install that has pytorch installed. The proper external evaluation initialization sequence is now: "
    ExternalEvaluate
    ExternalEvaluateImportExportPrivate`$ImporterPythonSession =
    StartExternalSession[“Python” → “String”]
    session = StartExternalSession[“Python”]
    "

  3. “trainedOpenPose = NetReplacePart[openpose, rule]” fails unless I modify the preceding line to read:
    rule = Thread[replacenames → Normal[parametersReshape]];
    that is, I have added a “Normal” to strip out the NumericArray[…,“Real32”] commands

At the end everything runs, but the model fails to recognize Ichiro properly, giving only one pair of points that are not even on his body… PLEASE HELP! Thanks!

PoseEstimationTest.nb (1.22 MB)

Jonathan-san,

Thank you for your comment.
I’ve evaluated your notebook and my notebook in my new environment(v12.1) and they have recognized Ichiro properly.
It may be due to the different versions of Python(2.7.16 vs 3.7.4).

I attached my result of your notebook.

PoseEstimationTest.nb (1.87 MB)

1 Like

Kotaro-San,

Thank you so much for the quick reply – I really appreciate it! I am soooo excited about learning about neural networks and this seems like a terrific opportunity to get into it!

Could you perhaps also let me know what versions of numpy, pkl, and torch you are using? I can certainly switch to a python 3 anaconda package if that will resolve things, but I’d prefer to install all the correct packages this time around :slight_smile:

Again – my sincerest appreciation from Chicago, and I hope all is well with you in these difficult times!

Cheers,
Jon

Jonathan-san,

The versions of numpy, pkl, and torch I use are

Aaaaand… it works! Thanks so much, Kotaro-San :slight_smile:

For posterity’s sake, here are the things that had to happen to get it working with conda on OSX:

  1. Get the right version of python:
    “conda create -n python3 python=3.7 anaconda”

  2. Switch to that python virtualenv:
    “conda activate python3”

  3. Install pytorch for that virtualenv:
    “conda install pytorch”

  4. pqzmq (the python ↔ mathematica library) seems to already be installed with the conda distro, but just in case:
    “conda install pyzmq”

  5. Find the path to the conda python install:
    “which python”

  6. Register the conda python with mathematica:

ExternalEvaluate;
ExternalEvaluatePrivateresetCache[]
RegisterExternalEvaluator[“Python”, “/opt/anaconda2/envs/python3/bin/python”]

  1. Modify Kotaro-San’s ExternalEvaluate code to set the directory to the one containing the the .pth file:
    os.chdir(‘full path here’)

8)I also added a “Normal” to this line of Kotaro-San’s code, but I don’t know that it was essential:
rule = Thread[replacenames → Normal[parametersReshape]];

That’s it. Note that 1-5 are terminal commands, while 6-8 are within Mathematica. Enjoy!

1 Like