Maxbox Starter77
Maxbox Starter77
Maxbox Starter77
Machine Learning X
____________________________________________________________________________
maXbox Starter 77 – Unified Machine Learning
1/6
An example of this compromise exists in our domain, media
monitoring (at least traditionally), many customers expect an
almost perfect recall. They never want to miss an relevant article
about the subjects they are interested in. However precision is
not as important (albeit highly desirable), if you get a bit of
noise in the article feed with false positives to sort out, you
are usually fine.
2/6
• TensorFlow
• OpenCV
• Keras and ImageAI itself to install with $ pip3 install imageAI
Now download the TinyYOLOv3 model file (33.9 MB) that contains a pretrained
classification model that will be used for object detection:
https://sourceforge.net/projects/maxbox/files/Examples/EKON/EKON24/ImageDetector
/yolo-tiny.h5/download
Now put an image for detection in the input folder, for example: manmachine.jpg
Open now your preferred text editor for writing Python code (in my case maXbox)
and create a new file detector3.py or some valid file name.
model_path = "./models/yolo-tiny.h5"
input_path = "./input/manmachine.jpg"
output_path = "./output/manmachineout.jpg"
3/6
#loads model from path specified above using the setModelPath() class method.
detector.loadModel()
To detect only some of the objects above, I will need to call the
CustomObjects method and set the name of the object(s) we want to
detect to through. The rest are False by default.
In our example, we detect customized only person. But it detects a
fifth person as a combination of two persons sort of a man-machine
in it ;-)).
custom= detector.CustomObjects(person=True,boat=True,laptop=True,bottle=True)
detections = detector.detectCustomObjectsFromImage(custom_objects=custom, \
input_image=input_path, output_image_path=output_path,\
minimum_percentage_probability=10)
Another reason for the custom instance is that I can define the
threshold to find things. Unlike normal detectObjectsFromImage()
function, this needs an extra parameter which is “custom_object”
which accepts the dictionary returned by the CustomObjects()
function. In the sample below, we set the detection function to
report only detections we want:
for eachItem in detections:
print(eachItem["name"] , " : ", eachItem["percentage_probability"])
person : 11.582126468420029
person : 15.317463874816895
person : 25.40428638458252
person : 41.63033664226532
person : 42.076510190963745
integrate image detector compute ends...
elapsedSeconds:= 19.9037681927473
4/6
So we get 5 objects as persons with color frames and corresponding
probability. But we only have 4 persons, there must be 1 false
positive; on the other side there's no false negative as a 100%
recall. Funny but really effective man-machine detection!
Script detector2.py
detector = ObjectDetection()
model_path = "./models/yolo-tiny.h5"
input_path = "./input/manmachine.jpg"
output_path = "./output/manmachineout.jpg"
detector.loadModel()
#detection = detector.detectObjectsFromImage(input_image=input_path, \
# output_image_path=output_path)
#https://stackabuse.com/object-detection-with-imageai-in-python/
#https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/yolo-tiny.h5
#https://imageai.readthedocs.io/en/latest/detection/index.html
There are 80 possible objects that you can detect with the
ObjectDetection class, and they are as seen below (not ordered).
person, bicycle, car, motorcycle, airplane, bus,train, truck, boat, traffic
light, fire hydrant, stop_sign, parking meter, bench, bird, cat,dog, horse,
sheep, cow, elephant, bear, zebra, giraffe, backpack,umbrella, handbag, tie,
suitcase, frisbee, skis, snowboard, sports ball, kite,baseball bat, baseball
glove, skateboard, surfboard, tennis racket, bottle, wine glass, cup, fork,
knife, spoon, bowl, banana, apple, sandwich,range,broccoli, carrot, hot dog,
pizza, donot, cake, chair, couch, potted plant, bed, dining table, toilet, tv,
laptop, mouse, remote, keyboard, cell phone, microwave, oven, toaster, sink,
refrigerator, book, clock, vase, scissors, teddy bear, hair dryer, toothbrush.
5/6
The script and data can be found:
http://www.softwareschule.ch/examples/992_detector21_wget_integrate2.htm
http://www.softwareschule.ch/examples/detector2.htm
https://sourceforge.net/projects/maxbox/files/Examples/EKON/EKON24/ImageDete
ctor/
http://www.softwareschule.ch/examples/classifier_compare2confusion2.py.txt
Ref:
http://www.softwareschule.ch/box.htm
https://scikit-learn.org/stable/modules/
https://realpython.com/python-histograms/
https://imageai.readthedocs.io/en/latest/detection/index.html
Doc:
https://maxbox4.wordpress.com
6/6