CustomObjects doesn't work as documented
reubenfirmin opened this issue · 2 comments
reubenfirmin commented
With this code:
from imageai.Detection import VideoObjectDetection
import os
import cv2
import sys
def forFrame(frame_number, output_array, output_count):
print("FOR FRAME " , frame_number)
print("Output for each object : ", output_array)
print("Output count for unique objects : ", output_count)
print("------------END OF A FRAME --------------")
def forSeconds(second_number, output_arrays, count_arrays, average_output_count):
print("SECOND : ", second_number)
print("Array for the outputs of each frame ", output_arrays)
print("Array for output count for unique objects in each frame : ", count_arrays)
print("Output average count for unique objects in the last second: ", average_output_count)
print("------------END OF A SECOND --------------")
def forMinute(minute_number, output_arrays, count_arrays, average_output_count):
print("MINUTE : ", minute_number)
print("Array for the outputs of each frame ", output_arrays)
print("Array for output count for unique objects in each frame : ", count_arrays)
print("Output average count for unique objects in the last minute: ", average_output_count)
print("------------END OF A MINUTE --------------")
execution_path = os.getcwd()
video_detector = VideoObjectDetection()
video_detector.setModelTypeAsRetinaNet()
video_detector.setModelPath( os.path.join(execution_path , "retinanet_resnet50_fpn_coco-eeacb38b.pth"))
video_detector.loadModel()
filename=sys.argv[1]
custom_objects = video_detector.CustomObjects(person=True, bicycle=True, motorcycle=True)
video_detector.detectCustomObjectsFromVideo(
input_file_path=os.path.join(execution_path, filename),
output_file_path=os.path.join(execution_path, "traffic_detected"),
frames_per_second=10,
custom_objects=custom_objects,
per_second_function=forSeconds,
per_frame_function=forFrame,
per_minute_function=forMinute,
minimum_percentage_probability=30,
log_progress=True
)
(which I built following: https://github.com/OlafenwaMoses/ImageAI/blob/master/imageai/Detection/VIDEO.md)
I get this error:
/home/reubenfirmin/imageai/env/lib/python3.10/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
warnings.warn(
/home/reubenfirmin/imageai/env/lib/python3.10/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=None`.
warnings.warn(msg)
/home/reubenfirmin/imageai/env/lib/python3.10/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained_backbone' is deprecated since 0.13 and may be removed in the future, please use 'weights_backbone' instead.
warnings.warn(
/home/reubenfirmin/imageai/env/lib/python3.10/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights_backbone' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights_backbone=None`.
warnings.warn(msg)
Traceback (most recent call last):
File "/home/reubenfirmin/imageai/detect.py", line 36, in <module>
custom_objects = video_detector.CustomObjects(person=True, bicycle=True, motorcycle=True)
File "/home/reubenfirmin/imageai/env/lib/python3.10/site-packages/imageai/Detection/__init__.py", line 579, in CustomObjects
return self.__detector.CustomObjects(kwargs)
TypeError: ObjectDetection.CustomObjects() takes 1 positional argument but 2 were given
reubenfirmin commented
Workaround until source fixed:
class FixedVideoObjectDetection(VideoObjectDetection):
def __init__(self):
super().__init__()
def CustomObjects(self, **kwargs):
self._VideoObjectDetection__detector.CustomObjects(**kwargs)
OlafenwaMoses commented
@reubenfirmin Thanks for reporting this. The bug has been fixed in #787