Forums

Cannot run my flask,tensorflow, openCV code

Hey I am not able to figure out why the following code is not running. Please help me. I am new to machine learning and this is my college project

2021-02-13 10:09:13 *** Starting uWSGI 2.0.17.1 (64bit) on [Sat Feb 13 10:09:12 2021] ***
2021-02-13 10:09:13 compiled with version: 5.4.0 20160609 on 07 May 2020 19:40:56
2021-02-13 10:09:13 os: Linux-5.4.0-1020-aws #20-Ubuntu SMP Fri Jul 10 05:52:40 UTC 2020
2021-02-13 10:09:13 nodename: blue-liveweb6
2021-02-13 10:09:13 machine: x86_64
2021-02-13 10:09:13 clock source: unix
2021-02-13 10:09:13 pcre jit disabled
2021-02-13 10:09:13 detected number of CPU cores: 2
2021-02-13 10:09:13 current working directory: (unreachable)/etc/uwsgi/vassals
2021-02-13 10:09:13 detected binary path: /usr/local/bin/uwsgi
2021-02-13 10:09:13 *** dumping internal routing table ***
2021-02-13 10:09:13 [rule: 0] subject: path_info regexp: \.svgz$ action: addheader:Content-Encoding:gzip
2021-02-13 10:09:13 *** end of the internal routing table ***
2021-02-13 10:09:13 chdir() to /home/plazor/mysite
2021-02-13 10:09:13 limiting number of processes to 120...
2021-02-13 10:09:13 your processes number limit is 120
2021-02-13 10:09:13 your memory page size is 4096 bytes
2021-02-13 10:09:13 detected max file descriptor number: 123456
2021-02-13 10:09:13 building mime-types dictionary from file /etc/mime.types...
2021-02-13 10:09:13 552 entry found
2021-02-13 10:09:13 lock engine: pthread robust mutexes
2021-02-13 10:09:13 thunder lock: disabled (you can enable it with --thunder-lock)
2021-02-13 10:09:13 uwsgi socket 0 bound to UNIX address /var/sockets/plazor.pythonanywhere.com/socket fd 3
2021-02-13 10:09:13 Python version: 3.8.0 (default, Nov 14 2019, 22:29:45)  [GCC 5.4.0 20160609]
2021-02-13 10:09:13 Set PythonHome to /home/plazor/.virtualenvs/Face
2021-02-13 10:09:13 *** Python threads support is disabled. You can enable it with --enable-threads ***
2021-02-13 10:09:13 Python main interpreter initialized at 0xdd0020
2021-02-13 10:09:13 your server socket listen backlog is limited to 100 connections
2021-02-13 10:09:13 your mercy for graceful operations on workers is 60 seconds
2021-02-13 10:09:13 setting request body buffering size to 65536 bytes
2021-02-13 10:09:13 mapped 501384 bytes (489 KB) for 2 cores
2021-02-13 10:09:13 *** Operational MODE: preforking ***
2021-02-13 10:09:13 initialized 54 metrics
2021-02-13 10:09:13 WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0xdd0020 pid: 1 (default app)
2021-02-13 10:09:13 *** uWSGI is running in multiple interpreter mode ***
2021-02-13 10:09:13 gracefully (RE)spawned uWSGI master process (pid: 1)
2021-02-13 10:09:13 spawned uWSGI worker 1 (pid: 4, cores: 1)
2021-02-13 10:09:13 spawned 2 offload threads for uWSGI worker 1
2021-02-13 10:09:13 spawned uWSGI worker 2 (pid: 7, cores: 1)
2021-02-13 10:09:13 metrics collector thread started
2021-02-13 10:09:13 spawned 2 offload threads for uWSGI worker 2
2021-02-13 10:09:44 Sat Feb 13 10:09:44 2021 - received message 0 from emperor
2021-02-13 10:09:44 SIGINT/SIGQUIT received...killing workers...
2021-02-13 10:09:45 worker 1 buried after 1 seconds
2021-02-13 10:09:45 worker 2 buried after 1 seconds
2021-02-13 10:09:45 goodbye to uWSGI.
2021-02-13 10:09:45 chdir(): No such file or directory [core/uwsgi.c line 1610]
2021-02-13 10:09:45 VACUUM: unix socket /var/sockets/plazor.pythonanywhere.com/socket removed.

[edited by admin: formatting]

that's your server log. could you show your error log?

Hi, thanks for the reply. Sure here is the latest entry in my error log. I have fixed it though by adding the path properly.

2021-02-13

 05:12:40,595: Error running WSGI application
2021-02-13 05:12:40,596: FileNotFoundError: [Errno 2] No such file or directory: 'model.json'
2021-02-13 05:12:40,596:   File "/var/www/plazor_pythonanywhere_com_wsgi.py", line 16, in <module>
2021-02-13 05:12:40,596:     from main import app as application  # noqa
2021-02-13 05:12:40,596: 
2021-02-13 05:12:40,596:   File "/home/plazor/mysite/main.py", line 2, in <module>
2021-02-13 05:12:40,596:     from camera import VideoCamera
2021-02-13 05:12:40,596: 
2021-02-13 05:12:40,596:   File "/home/plazor/mysite/camera.py", line 6, in <module>
2021-02-13 05:12:40,596:     model = FacialExpressionModel("model.json", "model_weights.h5")
2021-02-13 05:12:40,596: 
2021-02-13 05:12:40,597:   File "/home/plazor/mysite/model.py", line 22, in __init__
2021-02-13 05:12:40,597:     with open(model_json_file, "r") as json_file:
2021-02-13 05:12:40,597: ***************************************************
2021-02-13 05:12:40,597: If you're seeing an import error and don't know why,
2021-02-13 05:12:40,597: we have a dedicated help page to help you debug: 
2021-02-13 05:12:40,597: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-02-13 05:12:40,597: ***************************************************

wait-- just to double check, that error has been fixed and no longer shows up?

so then are there any new errors? if not what do you mean by "your code isn't running"

Hi, yes that error doesn't show up anymore. But my web app isn't running. Also to confirm, this code is functioning on my PC, but not here. Which is probably because I don't know how to use PythonAnywhere yet

so there are no errors but it "isn't running"? (i'm confused / can you give more details?)

Sure, basically... The link is saying Error 502 backend... And there are no errors in my code... I think it might be because I don't exactly know how to deploy my code here... I am sorry if I am not able to explain it properly

Maybe seeing it might help... http://plazor.pythonanywhere.com/

Hi, when you see 502 errors, you might also check the server logs. I see you've got Segmentation Fault while trying to use libcuda. PythonAnywhere does not have a GPU with CUDA cores, so if your model relies on a GPU, then it will generally not work on PythonAnywhere.

We've got a help page about Machine Learning on PA: https://help.pythonanywhere.com/pages/MachineLearningInWebsiteCode/ maybe this could help?

Oh, and maybe check also this thread: https://www.pythonanywhere.com/forums/topic/28665/ .

Wow, thank you so much... I will check these links out and see if it works :)

Hi Pafk, thank you so much for the advice my code is running well as a task without any errors, so that's good. Unfortunately I am not sure how to connect the always-on task to a web app. Do you have any guides for that? Appreciate it :)

Hi, @plazor. Glad you've got your code running again! Regarding always-on tasks -- this is a general hint from this help page https://help.pythonanywhere.com/pages/AsyncInWebApps/ :

  • register the user's request for work somewhere by storing the details of the request somewhere, eg on the filesystem, or in a table in your database

  • respond immediately to the user and let them know the request is now in state "pending"

  • set up an Always-on task (if you have a paid account). You can use a Scheduled task instead, if you don't have a paid account, but your queue will only be processed when the scheduled task is scheduled. The job of the task is to monitor your task queue (eg the database), and pick jobs off one by one. Include some code to update the job status (eg, pending, under way, complete...)

  • give the user a way of checking on the progress of the job, either by asking them to refresh the page, or perhaps setting up an Ajax polling system.

And here is an introduction to always-on tasks: https://help.pythonanywhere.com/pages/AlwaysOnTasks

Since each case is different, we don't have a step by step tutorial which would fit everyone's code yet :)