-
-
Save OlafenwaMoses/38e68a0f3bcb7350785b67d2e6bc06ce to your computer and use it in GitHub Desktop.
from imageai.Detection import ObjectDetection | |
import os | |
execution_path = os.getcwd() | |
detector = ObjectDetection() | |
detector.setModelTypeAsRetinaNet() | |
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.1.0.h5")) | |
detector.loadModel() | |
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image.jpg"), output_image_path=os.path.join(execution_path , "imagenew.jpg")) | |
for eachObject in detections: | |
print(eachObject["name"] , " : " , eachObject["percentage_probability"] ) |
!pip install tensorflow
!pip install opencv-python
!pip install keras
!pip install numpy
!pip install imageaifrom imageai.Detection import ObjectDetection
import osexecution_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 , "1598954196.053694.jpg"), output_image_path=os.path.join(execution_path , "an.jpg"))for eachObject in detections:
print(eachObject["name"] , " : " , eachObject["percentage_probability"] )AttributeError Traceback (most recent call last)
in
4 execution_path = os.getcwd()
5
----> 6 detector = ObjectDetection()
7 detector.setModelTypeAsRetinaNet()
8 detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))c:\users\asus\appdata\local\programs\python\python38\lib\site-packages\imageai\Detection__init__.py in init(self)
86 self.__yolo_model_image_size = (416, 416)
87 self.__yolo_boxes, self.__yolo_scores, self.__yolo_classes = "", "", ""
---> 88 self.sess = K.get_session()
89
90 # Unique instance variables for TinyYOLOv3.AttributeError: module 'keras.backend' has no attribute 'get_session'
same here
I don't want to save images that can not be detected so what can I do ?
To detect the object from the image from scratch using python; Click here I found the best article https://debuggingsolution.blogspot.com/2022/02/object-detection-from-scratch-in-python.html
Here's what the above code is doing:
- We first import the ObjectDetection class from the ImageAI library.
- We then create an instance of the ObjectDetection class and set the model type to RetinaNet.
- We then set the model path to the path of the RetinaNet model file that we downloaded earlier.
- We then load the model into the ObjectDetection class instance.
- We then call the detectObjectsFromImage method, passing in the input image path and the output image path.
- We then print the name of the object and the percentage probability that the object detected is the correct one.
!pip install tensorflow
!pip install opencv-python
!pip install keras
!pip install numpy
!pip install imageai
from imageai.Detection import ObjectDetection
import os
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 , "1598954196.053694.jpg"), output_image_path=os.path.join(execution_path , "an.jpg"))
for eachObject in detections:
print(eachObject["name"] , " : " , eachObject["percentage_probability"] )
AttributeError Traceback (most recent call last)
in
4 execution_path = os.getcwd()
5
----> 6 detector = ObjectDetection()
7 detector.setModelTypeAsRetinaNet()
8 detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
c:\users\asus\appdata\local\programs\python\python38\lib\site-packages\imageai\Detection_init_.py in init(self)
86 self.__yolo_model_image_size = (416, 416)
87 self.__yolo_boxes, self.__yolo_scores, self.__yolo_classes = "", "", ""
---> 88 self.sess = K.get_session()
89
90 # Unique instance variables for TinyYOLOv3.
AttributeError: module 'keras.backend' has no attribute 'get_session'