Skip to content

Instantly share code, notes, and snippets.

View OlafenwaMoses's full-sized avatar
💭
Coding the future....

MOSES OLAFENWA OlafenwaMoses

💭
Coding the future....
View GitHub Profile
@OlafenwaMoses
OlafenwaMoses / custom_hololens_detection.py
Created August 1, 2019 13:40
Code for detection Hololens in pictures using a trained custom model
from imageai.Detection.Custom import CustomObjectDetection
detector = CustomObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath("hololens-ex-60--loss-2.76.h5")
detector.setJsonPath("detection_config.json")
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image="holo3.jpg", output_image_path="holo3-detected.jpg")
for detection in detections:
print(detection["name"], " : ", detection["percentage_probability"], " : ", detection["box_points"])
@OlafenwaMoses
OlafenwaMoses / custom_detection_model_evaluation.py
Created August 1, 2019 13:21
Code to evaluate saved detection models using ImageAI
from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory="hololens")
trainer.evaluateModel(model_path="hololens/models", json_path="hololens/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5)
@OlafenwaMoses
OlafenwaMoses / custom_detection_training.py
Created August 1, 2019 12:55
Code for training custom object detection model with ImageAI
from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory="hololens")
trainer.setTrainConfig(object_names_array=["hololens"], batch_size=4, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5")
trainer.trainModel()
@OlafenwaMoses
OlafenwaMoses / pascal_voc.xml
Created August 1, 2019 09:36
The Pascal VOC Annotation sample
<annotation>
<folder>images</folder>
<filename>image (49).jpg</filename>
<path>mypath\images\image (49).jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>310</width>
<height>162</height>
from imageai.Prediction.Custom import CustomImagePrediction
import os
predictor = CustomImagePrediction()
predictor.setModelPath(model_path="transfer_trained_fruits_model_ex-050_acc-0.862500.h5")
predictor.setJsonPath(model_json="model_class.json")
predictor.loadFullModel(num_objects=5)
prediction, probability = predictor.predictImage(image_input=os.path.join(os.getcwd(), "sample.jpg"), result_count=1)
print(prediction, " :", probability)
from imageai.Prediction.Custom import ModelTraining
trainer = ModelTraining()
trainer.setModelTypeAsResNet()
trainer.setDataDirectory("fruits")
trainer.trainModel(num_objects=5, num_experiments=50, enhance_data=True, save_full_model=True, batch_size=32, show_network_summary=True, transfer_from_model="resnet50_weights_tf_dim_ordering_tf_kernels.h5", initial_num_objects=1000, transfer_with_full_training=True)
{'success': True,
'predictions': [{'y_min': 197, 'x_max': 396, 'x_min': 254, 'label': 'person', 'y_max': 394, 'confidence': 0.9963659},
{'y_min': 253, 'x_max': 349, 'x_min': 47, 'label': 'person', 'y_max': 563, 'confidence': 0.9960499},
{'y_min': 205, 'x_max': 764, 'x_min': 617, 'label': 'person', 'y_max': 381, 'confidence': 0.9950463},
{'y_min': 269, 'x_max': 1001, 'x_min': 647, 'label': 'person', 'y_max': 559, 'confidence': 0.9885887},
{'y_min': 233, 'x_max': 346, 'x_min': 184, 'label': 'person', 'y_max': 454, 'confidence': 0.97972304},
{'y_min': 194, 'x_max': 1001, 'x_min': 894, 'label': 'person', 'y_max': 285, 'confidence': 0.9065306},
{'y_min': 74, 'x_max': 278, 'x_min': 229, 'label': 'person', 'y_max': 243, 'confidence': 0.6799101},
{'y_min': 224, 'x_max': 897, 'x_min': 636, 'label': 'person', 'y_max': 455, 'confidence': 0.5133961},
{'y_min': 501, 'x_max': 353,
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace appone
{
const request = require("request")
const fs = require("fs")
image_stream = fs.createReadStream("office.png")
var form = {"image":image_stream}
//REMEMBER TO REPLACE IP '165.22.72.67' below with the IP of your Ubuntu server
request.post({url:"http://165.22.72.67:80/v1/vision/detection", formData:form},function(err,res,body){
import requests
image_data = open("office.png","rb").read()
#REMEMBER TO REPLACE IP '165.22.72.67' below with the IP of your Ubuntu server
response = requests.post("http://165.22.72.67:80/v1/vision/detection",files={"image":image_data}).json()
print(response)