arunponnusamy / cvlib

A simple, high level, easy to use, open source Computer Vision library for Python.
http://arunponnusamy.com/cvlib/
MIT License
647 stars 127 forks source link

Attribute error on module cvlib #5

Closed Kidist-Abraham closed 5 years ago

Kidist-Abraham commented 5 years ago

hey @arunponnusamy I installed cvlib via pip and try a simple code like

import cvlib as cv import cv2

cap=cv2.VideoCapture("std_camera.mp4") while True: ret,image=cap.read() faces, confidences = cv.detect_face(image) print(faces) print(confidences)
if cv2.waitKey(1) & 0xFF==ord('q'): break cv2.release() cv2.destroyAllWindows()

but it has an attribute error logging module 'cvlib' has no attribute 'detect_face'

I also tried it with python3 but still got that error.

arunponnusamy commented 5 years ago

Hello @Kidist-Abraham , this is weird. Have you installed the dependencies ? pip install numpy opencv-python requests progressbar I would suggest to stick to Python3 for using cvlib. Are you using pip3 for installing the package for python3 ?

Kidist-Abraham commented 5 years ago

hey, The problem was the name of my python code. It was cvlib.py. I think the program took my code as the cvlib module. Anyway i changed the name and it works fine. Thank you.

mrudhula commented 5 years ago

@arunponnusamy with that pkg 'pip install numpy opencv-python requests progressbar' also my problem is not getting solved 'ModuleNotFoundError: No module named 'cvlib''

arunponnusamy commented 5 years ago

@mrudhula May I know the python version you are working with and the command you are trying to execute to run the script ?

suvodeepdebnath commented 4 years ago

import cvlib as cv

Its not working..Help me to fix the error.

Using TensorFlow backend.

ImportError Traceback (most recent call last)

in () 2 import numpy as np 3 import cv2 ----> 4 import cvlib as cv 5 import matplotlib.pyplot as plt 6 from cvlib.object_detection import draw_bbox ~/anaconda3/envs/carnd-term1/lib/python3.5/site-packages/cvlib/__init__.py in () 6 from .face_detection import detect_face 7 from .object_detection import detect_common_objects ----> 8 from .gender_detection import detect_gender 9 from .utils import get_frames, animate ~/anaconda3/envs/carnd-term1/lib/python3.5/site-packages/cvlib/gender_detection.py in () 2 import os 3 import numpy as np ----> 4 from keras.utils import get_file 5 from keras.models import load_model 6 from keras.preprocessing.image import img_to_array ImportError: cannot import name 'get_file'
suvodeepdebnath commented 4 years ago

import cvlib as cv Its not working..Help me to fix it.

Using TensorFlow backend.

ImportError Traceback (most recent call last)

in () 2 import numpy as np 3 import cv2 ----> 4 import cvlib as cv 5 import matplotlib.pyplot as plt 6 from cvlib.object_detection import draw_bbox ~/anaconda3/envs/carnd-term1/lib/python3.5/site-packages/cvlib/__init__.py in () 6 from .face_detection import detect_face 7 from .object_detection import detect_common_objects ----> 8 from .gender_detection import detect_gender 9 from .utils import get_frames, animate ~/anaconda3/envs/carnd-term1/lib/python3.5/site-packages/cvlib/gender_detection.py in () 2 import os 3 import numpy as np ----> 4 from keras.utils import get_file 5 from keras.models import load_model 6 from keras.preprocessing.image import img_to_array ImportError: cannot import name 'get_file'
arunponnusamy commented 4 years ago

@suvodeepdebnath Can you check whether Keras has been installed properly ?

import keras
print(keras.__version__)
AnalyticsInAction commented 4 years ago

I have the same "No module named 'cvlib'` error.
Exact traceback from my conda virtual environment is

(cvlibenv) C:\Users\Steve\Desktop\Python Projects\cvis>testcv.py Traceback (most recent call last): File "C:\Users\Steve\Desktop\Python Projects\cvis\testcv.py", line 1, in <module> import cvlib ModuleNotFoundError: No module named 'cvlib'

When checking if Keras if properly installed via the script below I get : " 2.2.4-tf"

import tensorflow as tf print(tf.keras.__version__)

As for some additional background, when I 'conda list' to summarize libraries installed I get the following list of packages and versions. Note I am running Tensor flow 1.14.0, but also get the same error in a tensorflow 2.0.0 environment as well.

`(cvlibenv) C:\Users\Steve\Desktop\Python Projects\cvis>conda list packages in environment at C:\Users\Steve\Anaconda3\envs\cvlibenv:

Name Version Build Channel _tflow_select 2.1.0 gpu absl-py 0.8.1 py37_0 astor 0.8.0 py37_0 blas 1.0 mkl ca-certificates 2019.11.27 0 certifi 2019.11.28 py37_0 chardet 3.0.4 pypi_0 pypi cudatoolkit 10.0.130 0 cudnn 7.6.4 cuda10.0_0 cvlib 0.2.3 pypi_0 pypi gast 0.3.2 py_0 grpcio 1.16.1 py37h351948d_1 h5py 2.8.0 py37hf7173ca_2 hdf5 1.8.20 hac2f561_1 icc_rt 2019.0.0 h0cc432a_1 idna 2.8 pypi_0 pypi imageio 2.6.1 pypi_0 pypi imutils 0.5.3 pypi_0 pypi intel-openmp 2019.4 245 jpeg 9b hb83a4c4_2 keras 2.3.1 pypi_0 pypi keras-applications 1.0.8 py_0 keras-preprocessing 1.1.0 py_1 libopencv 3.4.2 h20b85fd_0 libpng 1.6.37 h2a8f88b_0 libprotobuf 3.11.2 h7bd577a_0 libtiff 4.1.0 h56a325e_0 markdown 3.1.1 py37_0 mkl 2019.4 245 mkl-service 2.3.0 py37hb782905_0 mkl_fft 1.0.15 py37h14836fe_0 mkl_random 1.1.0 py37h675688f_0 numpy 1.17.4 py37h4320e6b_0 numpy-base 1.17.4 py37hc3f5095_0 opencv 3.4.2 py37h40b0b35_0 openssl 1.1.1d he774522_3 pillow 6.2.1 pypi_0 pypi pip 19.3.1 py37_0 progressbar 2.5 pypi_0 pypi protobuf 3.11.2 py37h33f27b4_0 py-opencv 3.4.2 py37hc319ecb_0 pyreadline 2.1 py37_1 python 3.7.5 h8c8aaf0_0 pyyaml 5.2 pypi_0 pypi requests 2.22.0 pypi_0 pypi scipy 1.3.2 py37h29ff71c_0 setuptools 42.0.2 py37_0 six 1.13.0 py37_0 sqlite 3.30.1 he774522_0 tensorboard 1.14.0 py37he3c9ec2_0 tensorflow 1.14.0 gpu_py37h5512b17_0 tensorflow-base 1.14.0 gpu_py37h55fc52a_0 tensorflow-estimator 1.14.0 py_0 tensorflow-gpu 1.14.0 h0d30ee6_0 termcolor 1.1.0 py37_1 urllib3 1.25.7 pypi_0 pypi vc 14.1 h0510ff6_4 vs2015_runtime 14.16.27012 hf0eaf9b_1 werkzeug 0.16.0 py_0 wheel 0.33.6 py37_0 wincertstore 0.2 py37_0 wrapt 1.11.2 py37he774522_0 xz 5.2.4 h2fa13f4_4 zlib 1.2.11 h62dcd97_3 zstd 1.3.7 h508b16e_0 `

Any ideas?

arunponnusamy commented 4 years ago

@AnalyticsInAction I haven't actually tested with conda. Can you try installing cvlib via pip ?

AnalyticsInAction commented 4 years ago

I installed cvlib via pip when I got that error (cvlib doesn't appear to be an option via conda). The rest of the required packages were installed via conda.

I did wonder whether this was something linked to the conda virtual environment, and tried to do an cvlib install in a "VENV" virtual environment (with the following method)

python -m venv cvliben cvliben\Scripts\activate.bat pip install opencv-python tensorflow pip install cvlib

but using this methodology - I get another error "ModuleNotFoundError: No module named 'keras.utils'; 'keras' is not a package"

if I pip list the following package versions are listed `(cvliben) C:\Users\Steve\Desktop\Python Projects\cvis>pip list Package Version


absl-py 0.9.0 astor 0.8.1 cachetools 4.0.0 certifi 2019.11.28 chardet 3.0.4 cvlib 0.2.3 gast 0.2.2 google-auth 1.10.0 google-auth-oauthlib 0.4.1 google-pasta 0.1.8 grpcio 1.26.0 h5py 2.10.0 idna 2.8 imageio 2.6.1 imutils 0.5.3 Keras 2.3.1 Keras-Applications 1.0.8 Keras-Preprocessing 1.1.0 Markdown 3.1.1 numpy 1.17.4 oauthlib 3.1.0 opencv-python 4.1.2.30 opt-einsum 3.1.0 Pillow 6.2.1 pip 18.1 progressbar 2.5 protobuf 3.11.1 pyasn1 0.4.8 pyasn1-modules 0.2.7 PyYAML 5.2 requests 2.22.0 requests-oauthlib 1.3.0 rsa 4.0 scipy 1.4.1 setuptools 42.0.2 six 1.13.0 tensorboard 2.0.2 tensorflow 2.0.0 tensorflow-estimator 2.0.1 termcolor 1.1.0 urllib3 1.25.7 Werkzeug 0.16.0 wheel 0.33.6 wrapt 1.11.2`

I also tried uninstalling and reinstalling Keras with

pip uninstall keras pip install keras --upgrade

but the error persisted.

Perhaps its a conflict between different version permutations? Could you outline the exact versions of Python, Tensorflow, Opencv, and Cvlib you are using in your current environment. I will l see if replicating it might resolve my current issues.

Cheers Steve

arunponnusamy commented 4 years ago

This seems to be a weird issue on Windows. Can you try importing keras on a python console just to check it is properly installed.

$python3
>>import keras
>>print(keras.__version__)

Also if possible can you try using cvlib on linux/macos ? or probably on Google Colab ? I am using

Python 3.6.8, 
TensorFlow 1.15.0
opencv-python 4.1.0.25
keras 2.2.4
cvlib 0.2.3
AnalyticsInAction commented 4 years ago

Thanks for the additional suggestions. I will be offline for the Christmas break, but will revisit these suggestions once I am back online. Cheers Steve

AnalyticsInAction commented 4 years ago

Yes - works fine in Colab. Simple test here : Might just side step the issue and run in Linux environment rather than windows. Cheers Steve

arunponnusamy commented 4 years ago

I think it should also work on Windows with the plain command prompt and pip (without any other external things like Anaconda).

AnalyticsInAction commented 4 years ago

Thanks. I set up a virtual environment using VENV on my Windows 10 machine, and installed the exact versions you specified above - and cvlib now works fine. So I will put it down to some interaction between library versions. Thanks for your advice and suggestions.

arunponnusamy commented 4 years ago

@AnalyticsInAction Are you using Anaconda for this setup ?

AnalyticsInAction commented 4 years ago

@arunponnusamy Apologies, thought I had replied to the last message weeks ago. The setup that worked didn't involve Anaconda. Just standard pip install in a VENV virtual environment using a requirements file to specify the exact versions of the libraries you outlined above.

so

  1. Create a new environment python -m venv cvliben

  2. Navigate to the directory cd C:\Users\Steve\Desktop\Python Projects\cvis

  3. Activate the virtual environment cvliben\Scripts\activate.bat

  4. Install the requirements.txt file pip install -r requirements.txt

Then I just ran the cvlib scripts and everything worked. Cheers Steve

AISWARYA2019 commented 4 years ago

I got the same error while importing "cvlib". import cvlib python error cvlib Please help, thanks.