Ejemplo n.º 1
0
def test_recognition_model_resnet():

    predictor = ImageClassification()
    predictor.setModelTypeAsResNet50()
    predictor.setModelPath(os.path.join(main_folder, "data-models", "resnet50_imagenet_tf.2.0.h5"))
    predictor.loadModel()
    predictions, probabilities = predictor.classifyImage(image_input=os.path.join(main_folder, main_folder, "data-images", "1.jpg"))

    assert isinstance(predictions, list)
    assert isinstance(probabilities, list)
    assert isinstance(predictions[0], str)
    assert isinstance(probabilities[0], float)
Ejemplo n.º 2
0
class AI:
    def __init__(self):
        self.execution_path = os.getcwd()

    def init_object_detection(self):
        #import the model
        self.detector = ObjectDetection()
        self.detector.setModelTypeAsRetinaNet()
        self.detector.setModelPath(
            os.path.join(self.execution_path, "resnet50_coco_best_v2.1.0.h5"))
        self.detector.loadModel()

    def grab_object_tags(self, frame, timestamp):
        detections = self.detector.detectObjectsFromImage(
            input_image=frame,
            output_image_path=frame,
            minimum_percentage_probability=30)

        tags = []
        for eachObject in detections:
            t = {
                "tag": eachObject["name"],
                "probability": eachObject["percentage_probability"],
                "location": eachObject["box_points"]
            }
            tags.append(t)

        return {"timestamp": timestamp, "tags": tags}

    def init_image_classification(self):
        # import the model
        self.prediction = ImageClassification()
        self.prediction.setModelTypeAsResNet50()
        self.prediction.setModelPath(
            os.path.join(self.execution_path, "resnet50_imagenet_tf.2.0.h5"))
        self.prediction.loadModel()

    def grab_image_tags(self, frame, timestamp):
        predictions, probabilities = self.prediction.classifyImage(
            frame, result_count=10)
        for eachPrediction, eachProbability in zip(predictions, probabilities):
            print(eachPrediction, " : ", eachProbability)
Ejemplo n.º 3
0
def detectobjectinimage():
    path = os.getcwd()
    image_prediction = ImageClassification()
    image_prediction.setModelTypeAsResNet50()
    image_prediction.setModelPath(
        os.path.join(path, "resnet50_imagenet_tf.2.0.h5"))
    image_prediction.loadModel()

    predictions, percentage_probabilities = image_prediction.classifyImage(
        os.path.join(path, "/home/akwa/PycharmProjects/remindme/img.jpg"),
        result_count=10)

    for eachPrediction, eachProbability in zip(predictions,
                                               percentage_probabilities):
        print(eachPrediction, " : ", eachProbability)
        result = "Cup wasn't detected, hence, user hasn't drank water today"
        vampire = 'Raid come to our aid, we are dying!!!'
        if eachPrediction == "mosquito_net":
            detection_window(vampire)
        break
Ejemplo n.º 4
0
from imageai.Classification import ImageClassification
import os
executionpath = os.getcwd()
print(executionpath)
detection = ImageClassification()
detection.setModelTypeAsResNet50()
detection.setModelPath(executionpath + "/resnet50_imagenet_tf.2.0.h5")
detection.loadModel()
detections, percentageprobabilites = detection.classifyImage("Testimage.jpg",
                                                             result_count=5)
for Index in range(len(detections)):
    print(detections[Index], ":", percentageprobabilites[Index])
Ejemplo n.º 5
0
from imageai.Classification import ImageClassification
import os

execution_path = os.getcwd()

prediction = ImageClassification()
prediction.setModelTypeAsResNet50()
prediction.setModelPath(
    os.path.join(execution_path, "resnet50_imagenet_tf.2.0.h5")
)  # Download the model via this link https://github.com/OlafenwaMoses/ImageAI/releases/tag/1.0
prediction.loadModel()

predictions, probabilities = prediction.classifyImage(os.path.join(
    execution_path, "1.jpg"),
                                                      result_count=10)
for eachPrediction, eachProbability in zip(predictions, probabilities):
    print(eachPrediction, " : ", eachProbability)