Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'pnet' is not defined #14

Open
geek-ash opened this issue Aug 23, 2020 · 12 comments
Open

NameError: name 'pnet' is not defined #14

geek-ash opened this issue Aug 23, 2020 · 12 comments

Comments

@geek-ash
Copy link

When I run the server.py, the page loads correctly. But, when I upload a pic and click on submit, "NameError: name 'pnet' is not defined" appears. I am running in CPU mode, and I have installed all the required libraries in a virtualenv running on python 3.6.8.
Kindly help @tamerthamoqa
Thanks in Advance.
FireShot Capture 010 - NameError_ name 'pnet' is not defined __ Werkzeug Debugger - 127 0 0 1

@tamerthamoqa
Copy link
Owner

Hi geek-ash,

Could you specify what Operating System you are working on? I have tried to recreate this issue on Ubuntu 18.04 on a virtualenv and a conda environment but I have found no issues.

@geek-ash
Copy link
Author

I am working on Windows 10 - Home (64).

@tamerthamoqa
Copy link
Owner

A rather strange suggestion, but try installing numpy version 1.16.2 instead of version 1.14

@geek-ash
Copy link
Author

I already changed it to 1.16.1. I tried 1.16.2 too as you told but to no avail.

@tamerthamoqa
Copy link
Owner

I will try recreating this issue on Windows 10 tomorrow hopefully, could you provide a screenshot of your installed packages in the virtualenv by doing a pip list command?

@geek-ash
Copy link
Author

Annotation 2020-08-23 142005
Annotation 2020-08-23 142116

@tamerthamoqa
Copy link
Owner

tamerthamoqa commented Aug 25, 2020

Hello geek-ash,

I am honestly confused. I have tried recreating this issue on Windows 10 on a virtualenv and conda environment but I also have had no issues. I have also tried downloading the project as a zip file instead of a git clone command in case the compression caused issues in certain files but I also have had no issues.

Here is the list from the pip list command for my virtualenv:
pip_list

I have tried installing the tensorflow-estimator package and downgraded the gast package in the case any of the packages was causing the issue but I also have had no issues. Could you specify the steps you made while preparing the project? Because I honestly have no idea what is causing the issue on your end.

@geek-ash
Copy link
Author

I replicated my venv with the packages you posted above (pip list) but to no avail.
Following are the steps I followed:

  1. I created a virtualenv using the 'python36 -m virtualenv venv5'
  2. Downloaded the project as a zip file. then Extracted it and copied all the contents in my venv5
  3. Downloaded the model and extracted it.
  4. Then I edited the requirements_cpu.txt file to make it the same as the packages and versions you posted in the above comment (pip list).
  5. Then I run the command pip3 install -r requirements_cpu.txt on the cmd in my active venv5.
  6. Copied the 4 model files to the folder named model in the venv5 so that the path of the 20170512-110547.pb is ...\venv5\model\20170512-110547\20170512-110547.pb.
  7. Then run the following three commands on the cmd
    set FLASK_ENV=development
    set FLASK_APP=server.py
    flask run
  8. Then I opened http://127.0.0.1:5000/ in chrome.
  9. It showed that no it could not find 'lib'. So, I checked my venv5 folder and found that the 'lib' folder I copied from the project went into the 'Lib' folder that was created with the venv5. So, I renamed that folder as 'lib'.
  10. Then I reloaded the page in chrome, and it worked!
  11. Then I clicked on 'Choose File' and selected a picture of mine in jpg format.
  12. Then upon clicking 'Submit' the error 'NameError: name 'pnet' is not defined' came on the webpage!
    This is where I am stuck.

@geek-ash
Copy link
Author

BTW, I am running on my CPU. Hence, I don't have CUDA. I have just installed the requirements_cpu.txt.

@tamerthamoqa
Copy link
Owner

tamerthamoqa commented Aug 25, 2020

The issue is that you are running the server using the 'flask run' command, the models get defined and instantiated in the "if __ name __ == '__ main __ ' :" block, but because you are using the flask run command it makes __ name __ not equal to '__ main __' in this case, so the execution does not go through that block, and the MTCNN model (pnet, rnet, onet) and FaceNet model do not get defined and instantiated which causes your issue 'pnet is not defined'.

In order to solve this, you can just call 'python server.py' and the execution would run correctly. If you wish to use the 'flask run' method, then you should move the code inside the "if __ name __ == '__ main __':" block to the top of the code under the allowed_set variable and delete the 'serve(app=app, host='0.0.0.0', port=5000)' statement and the code would work in your case.

StackOverflow reference: https://stackoverflow.com/questions/58564162/what-is-the-difference-between-using-flask-run-vs-python-app-py-vs-python-m-fla

I will add a note about this in the README file, please do notify me if other issues arise.

@geek-ash
Copy link
Author

Hey Tamer,
Thank you for the help! I really missed that :)

@tamerthamoqa
Copy link
Owner

tamerthamoqa commented Aug 25, 2020

Glad it worked 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants