mpatacchiola / deepgaze

Computer Vision library for human-computer interaction. It implements Head Pose and Gaze Direction Estimation Using Convolutional Neural Networks, Skin Detection through Backprojection, Motion Detection and Tracking, Saliency Map.
MIT License
1.79k stars 478 forks source link

Errors when running in Colab #81

Closed nyck33 closed 5 years ago

nyck33 commented 5 years ago

I git clone'd both master and 2.0 branches and tried to install but I keep getting a no module name 'deepgaze' error in the face_center_color_classification notebook's first cell.

(base) nobu@gold3forever /media/nobu/Ubuntu Backup1/DeepLearning/PornFlow/deepgaze_py2 (master) $ sudo python setup.py install
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'include_package_data'
  warnings.warn(msg)
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/bayes_filter.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/cnn_head_pose_estimator.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/color_classification.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/color_detection.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/face_detection.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/face_landmark_detection.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/haar_cascade.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/head_pose_estimation.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/mask_analysis.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/motion_detection.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/motion_tracking.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/saliency_map.py -> build/lib.linux-x86_64-2.7/deepgaze
copying deepgaze/__init__.py -> build/lib.linux-x86_64-2.7/deepgaze
running install_lib
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/deepgaze-0.1.egg-info
Writing /usr/local/lib/python2.7/dist-packages/deepgaze-0.1.egg-info
mpatacchiola commented 5 years ago

Hi @nyck33

There may be a problem with the link to the libraries in your system, with the module not found. Try the following:

After installing deepgaze through sudo python setup.py install open a new terminal. Start a new python console through the command python2 (for Deepgaze 1.0) or python3 (for Deepgaze 2.0). Now just try to import the module writing in the python console import deepgaze. If the module is correctly installed you should not get any error, otherwise please report the error that you get.

nyck33 commented 5 years ago

I have it running online in Colab now but getting

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-22-ba7b5b584cba> in <module>()
----> 1 cx, cy = my_mask_analyser.returnMaxAreaCenter(image_mask)
      2 cnt = my_mask_analyser.returnMaxAreaContour(image_mask)

/content/deepgaze/deepgaze/mask_analysis.py in returnMaxAreaCenter(self, mask)

ValueError: too many values to unpack (expected 2)

I was getting another error before that related to def returnMaxAreaCenter() for the line contours, hierarchy = cv2.findContours(mask, 1, 2) so I added a _ in front of contours to make it _, contours, hierarchy = cv2.findContours(mask, 1, 2)

mpatacchiola commented 5 years ago

This may be due to incompatibility between the version of Deepgaze installed and the version of OpenCV. Please check your setup, in particular be sure that you are using OpenCV 2 with Deepgaze 1.0 or OpenCV 3 with Deepgaze 2.0.

nyck33 commented 5 years ago

Will do. Thanks for replying.

On Wed, 10 Jul 2019 at 16:11, Massimiliano Patacchiola < notifications@github.com> wrote:

Hi @nyck33 https://github.com/nyck33

There may be a problem with the link to the libraries in your system, with the module not found. Try the following:

After installing deepgaze through sudo python setup.py install open a new terminal. Start a new python console through the command python2 (for Deepgaze 1.0) or python3 (for Deepgaze 2.0). Now just try to import the module writing in the python console import deepgaze. If the module is correctly installed you should not get any error, otherwise please report the error that you get.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mpatacchiola/deepgaze/issues/81?email_source=notifications&email_token=AGAFZKIZTUVFP6LPW747T5TP6WKTHA5CNFSM4H7MM532YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZSVS5I#issuecomment-509958517, or mute the thread https://github.com/notifications/unsubscribe-auth/AGAFZKPI5JW3Z322CLLT2RLP6WKTHANCNFSM4H7MM53Q .

-- Nobutaka Github: https://github.com/nyck33 Blog: https://nobu-portfolio.blogspot.com/ Linkedin: https://www.linkedin.com/in/stayfit4ever/ Tel:0900344207 Skype: nobutaka.gold3@gmail.com Line: nobu_2018

nyck33 commented 5 years ago

@mpatacchiola I git cloned 2.0 version with command git clone https://github.com/mpatacchiola/deepgaze.git -b 2.0 --single-branch. Then I checked the opencv version on Colab which turned out to be 3.4.3. So I should be good to go I thought but still getting the Value Error per below:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-f45818827aea> in <module>()
      1 '''for i in range(len(a)):
      2     print(a[i])'''
----> 3 cx, cy = my_mask_analyser.returnMaxAreaCenter(image_mask)
      4 cnt = my_mask_analyser.returnMaxAreaContour(image_mask)

/usr/local/lib/python3.6/dist-packages/deepgaze/mask_analysis.py in returnMaxAreaCenter(self, mask)
     50         if(len(mask.shape) == 3):
     51             mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
---> 52         contours, hierarchy = cv2.findContours(mask, 1, 2)
     53         area_array = np.zeros(len(contours)) #contains the area of the contours
     54         counter = 0

ValueError: too many values to unpack (expected 2)

Reverting back to opencv 2 on Colab is a bit of work but I'll give it a shot. Regardless, the notebooks should work with either master (1.0) or 2.0?

mpatacchiola commented 5 years ago

Deepgaze 2.0 is still work in progress at the moment and it is possible that there may be a few hidden issues to fix. The notebooks should work with the version 2.0. @kamathhrishi is taking care of the porting at the moment, let's see if he can give a look to it...

mpatacchiola commented 5 years ago

@nyck33 for the moment you can simply substitute: contours, hierarchy = cv2.findContours(mask, 1, 2) with _, contours, hierarchy = cv2.findContours(mask, 1, 2) and then install again the library to make the change effective. This should be due to the fact that in OpenCV 3 the function cv2.findContours() now returns 3 values instead of 2. @kamathhrishi I think a simple patch consists in checking the version of OpenCV with a conditional operator and call the appropriate method. Something like this:

import cv2
(major, minor, _) = cv2.__version__.split(".")

if(major=='2'):
    contours, hierarchy = cv2.findContours(mask, 1, 2)
elif(major=='3'):
    _, contours, hierarchy = cv2.findContours(mask, 1, 2)

@nyck33 if you fix it, you can send a pull request on the 2.0 branch and I will add it to the repo.

nyck33 commented 5 years ago

@mpatacchiola I guess you already kind of solved it:) I was just looking for a way to detect profile faces (side faces) so have to move on at this time but hopefully someone else will find info above useful.

mpatacchiola commented 5 years ago

This has now been fixed in branch 2.0