Skip to content

Instantly share code, notes, and snippets.

@Ahanmr
Created June 19, 2018 07:22
Show Gist options
  • Save Ahanmr/4ba87aa8d24563bbf29131a34b9b99bc to your computer and use it in GitHub Desktop.
Save Ahanmr/4ba87aa8d24563bbf29131a34b9b99bc to your computer and use it in GitHub Desktop.
'''
Editor: Ahan M R
Date: 18-06-2018
Python 3.6.0
'''
#PS1 CROWD DETECTION IN THE CAFETERIA
'''
From imageAI API, we import Object detection and use it to detect the object classes in the image
'''
from imageai.Detection import ObjectDetection
import os
#os.getcwd gets the current working directory of the image
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image4.jpg"), output_image_path=os.path.join(execution_path , "imagenew4.jpg"))
for eachObject in detections:
print(eachObject["name"] + " : " + eachObject["percentage_probability"] )
@varunpilankar
Copy link

varunpilankar commented Mar 2, 2020

Does it work? Coz I tried to detect people with the image but it's throwing me below mentioned error.

Using TensorFlow backend.
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:493: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:494: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:495: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:496: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:497: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/dtypes.py:502: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
2020-03-02 16:33:00.083462: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/imageai/Detection/init.py", line 194, in detectObjectsFromImage
image = read_image_bgr(input_image)
File "/usr/local/lib/python3.5/dist-packages/imageai/Detection/keras_retinanet/utils/image.py", line 29, in read_image_bgr
image = np.asarray(Image.open(path).convert('RGB'))
File "/usr/local/lib/python3.5/dist-packages/PIL/Image.py", line 2809, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '/root/Crowd_Analysis/image4.jpg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "CrowdDetection.py", line 15, in
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image4.jpg"), output_image_path=os.path.join(execution_path , "imagenew4.jpg"))
File "/usr/local/lib/python3.5/dist-packages/imageai/Detection/init.py", line 272, in detectObjectsFromImage
raise ValueError("Ensure you specified correct input image, input type, output type and/or output image path ")
ValueError: Ensure you specified correct input image, input type, output type and/or output image path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment