from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="Vier_Onderdelen_Wit") trainer.setTrainConfig( object_names_array=["Schoepen_groot", "Schijf_zilver", "Kom", "Rotor"], batch_size=4, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel() trainer.setDataDirectory(data_directory="Vier_Onderdelen_Wit") evaluate = trainer.evaluateModel( model_path="Vier_Onderdelen_Wit/models", json_path="Vier_Onderdelen_Wit/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5) x = [] for i in range(len(evaluate)): map = evaluate[i]['map'] experiment = evaluate[i]['model_file'] x.append((map, experiment)) x.sort() text_file = open("maps_vier_onderdelen_wit.txt", "wt") for i in x: e = text_file.writelines(str(i) + "\n") text_file.close()
from imageai.Detection.Custom import DetectionModelTrainer ''' ["Rick Owens Ramones", "Rick Owens Geobaskets", "Rick Owens x Adidas Runners", "Rick Owens x Adidas Tech Runners", "Rick Owens x Adidas Level Runners", "Balenciaga Arenas", "Balenciaga Speed Sneaker", "Balenciaga Tripple S", "Common Project Achillies Low", "Common Project Chelsea Boot", "Dr Martens 1460"] ''' trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="shoetect") trainer.setTrainConfig(object_names_array=[ "Rick Owens Ramones", "Rick Owens Geobaskets", "Rick Owens x Adidas Runners", "Rick Owens x Adidas Tech Runners", "Rick Owens x Adidas Level Runners", "Balenciaga Arenas", "Balenciaga Speed Sneaker", "Balenciaga Tripple S", "Common Project Achillies Low", "Common Project Chelsea Boot", "Dr Martens 1460" ], batch_size=4, num_experiments=50, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer # Initialize the model trainer and set it to YOLO (YOLOv3 is optional) train = DetectionModelTrainer() train.setModelTypeAsYOLOv3() # Choose the name of your directory d_name = "tires" train.setDataDirectory(data_directory=d_name) train.setTrainConfig(object_names_array=[d_name], batch_size=4, num_experiments=203) train.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory( data_directory="/content/drive/My Drive/project data sets/data_cleaned") trainer.evaluateModel( model_path="/content/drive/My Drive/project data sets/data_cleaned/models", json_path= "/content/drive/My Drive/project data sets/data_cleaned/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5)
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="SymDescribeImages") metrics = trainer.evaluateModel( model_path="SymDescribeImages/models", json_path="SymDescribeImages/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5) print(metrics)
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="pallet") trainer.setTrainConfig(object_names_array=["pallet"], batch_size=10, num_experiments=150, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
# -*- coding: utf-8 -*- #Run this in colab or in a jupyter notebook """Prerequisites""" !pip3 install tensorflow-gpu==1.13.1 !pip3 install imageai --upgrade !wget https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5 """Change data_directory and object_names_array appropriately""" from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="/content/drive/My Drive/Football/") trainer.setTrainConfig(object_names_array=["Bundesliga", "EPL", "LaLiga"], batch_size=4, num_experiments=7, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel() """Pick the model with maximum mAP""" from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="/content/drive/My Drive/Football") trainer.evaluateModel(model_path="/content/drive/My Drive/Football/models", json_path="/content/drive/My Drive/Football/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5)
# get the absolute image path for the image from the annotation img_abs_path = os.path.join(images_directory, img_filename) if os.path.isfile(img_abs_path): # image corresponding to the annotation exists # print(img_abs_path + " exists") pass else: print(img_abs_path + " does not exists") os.remove(abs_annotation_file_path) print(abs_annotation_file_path + " Deleted") print(count) !wget https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5 -P '/gdrive/My Drive/BE Project 2019 - 2020/final_training_folder/models/' import os from imageai.Detection.Custom import DetectionModelTrainer model_trainer = DetectionModelTrainer() model_trainer.setModelTypeAsYOLOv3() model_trainer.setDataDirectory(data_directory_path) yolo_path = os.path.join(os.path.join(execution_path, "models"), "pretrained-yolov3.h5") model_trainer.setTrainConfig(object_names_array=["glass", "metal", "paper", "plastic"], batch_size=10, num_experiments=50, train_from_pretrained_model=yolo_path) model_trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer dataset_name = 'dataset' names = ['on', 'off'] trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=dataset_name) metrics = trainer.evaluateModel(model_path=dataset_name + "/models", json_path=dataset_name + "/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5) print(metrics)
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="hololens") # dataSet path on drive trainer.setTrainConfig( object_names_array=["hololens"], # Symbol name batch_size=4, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="smoker") trainer.setTrainConfig(object_names_array=["tobacco"], batch_size=4, num_experiments=200, train_from_pretrained_model="pretrained-yolov3.h5") #download pre-trained model via https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5 # If you are training to detect more than 1 object, set names of objects above like object_names_array=["hololens", "google-glass", "oculus", "magic-leap"] trainer.trainModel() """ SAMPLE RESULT Using TensorFlow backend. Generating anchor boxes for training images and annotation... Average IOU for 9 anchors: 0.78 Anchor Boxes generated. Detection configuration saved in hololens/json/detection_config.json Training on: ['hololens'] Training with Batch Size: 4 Number of Experiments: 200 Epoch 1/200 - 733s - loss: 34.8253 - yolo_layer_1_loss: 6.0920 - yolo_layer_2_loss: 11.1064 - yolo_layer_3_loss: 17.6269 - val_loss: 20.5028 - val_yolo_layer_1_loss: 4.0171 - val_yolo_layer_2_loss: 7.5175 - val_yolo_layer_3_loss: 8.9683 Epoch 2/200 - 648s - loss: 11.1396 - yolo_layer_1_loss: 2.1209 - yolo_layer_2_loss: 4.0063 - yolo_layer_3_loss: 5.0124 - val_loss: 7.6188 - val_yolo_layer_1_loss: 1.8513 - val_yolo_layer_2_loss: 2.2446 - val_yolo_layer_3_loss: 3.5229 Epoch 3/200
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="custom_detect_train_data") trainer.setTrainConfig(object_names_array=["wn"], batch_size=4, num_experiments=200, train_from_pretrained_model="pretrained-yolov3.h5") #download pre-trained model via https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5 # If you are training to detect more than 1 object, set names of objects above like object_names_array=["hololens", "google-glass", "oculus", "magic-leap"] trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="barbijo") trainer.evaluateModel(model_path="barbijo/models", json_path="barbijo/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5)
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="kangaroo") trainer.setTrainConfig(object_names_array=["kangaroo"], batch_size=8, num_experiments=50, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
# -*- coding: utf-8 -*- """ Created on Tue Sep 24 15:38:42 2019 @author: Gayatri """ from imageai.Detection.Custom import DetectionModelTrainer import os os.chdir('F:\Internship_CV\ImageAI_Model') trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory='hololens') trainer.setTrainConfig(object_names_array=['hololens'], batch_size=4, num_experiments=20, train_from_pretrained_model='pretrained-yolov3.h5') trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer #Setup the trainer and use model Yolov3 trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() #Set Data directory folder trainer.setDataDirectory(data_directory="tomato") #Objects, batch & experiments + pre-existing model # batch_size = number of training examples used in one iteration # num_experiments = number of iterations trainer.setTrainConfig(object_names_array=["red_cherry_tomato", "orange_cherry_tomato", "yellow_cherry_tomato", "green_cherry_tomato"], batch_size=1, num_experiments=1, train_from_pretrained_model="C:\\Users\\Max\\Desktop\\superAI\\tomato\\models\\detection_model-ex-013--loss-0108.641.h5") #Start training trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="drone") trainer.setTrainConfig(object_names_array=[ "person", "light_motor_vehicle", "heavy_motor_vehicle" ], batch_size=4, num_experiments=200, train_from_pretrained_model="pretrained-yolov3.h5") #download pre-trained model via https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5 # If you are training to detect more than 1 object, set names of objects above like object_names_array=["hololens", "google-glass", "oculus", "magic-leap"] trainer.trainModel() """ SAMPLE RESULT Using TensorFlow backend. Generating anchor boxes for training images and annotation... Average IOU for 9 anchors: 0.78 Anchor Boxes generated. Detection configuration saved in hololens/json/detection_config.json Training on: ['hololens'] Training with Batch Size: 4 Number of Experiments: 200 Epoch 1/200 - 733s - loss: 34.8253 - yolo_layer_1_loss: 6.0920 - yolo_layer_2_loss: 11.1064 - yolo_layer_3_loss: 17.6269 - val_loss: 20.5028 - val_yolo_layer_1_loss: 4.0171 - val_yolo_layer_2_loss: 7.5175 - val_yolo_layer_3_loss: 8.9683 Epoch 2/200
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="dataset") metrics = trainer.evaluateModel(model_path="dataset/models", json_path="dataset/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5) print(metrics)
import os import glob from imageai.Detection.Custom import DetectionModelTrainer execution_path = os.getcwd() models_path = os.path.join(execution_path, "doge-identification/models/") data_path = os.path.join(execution_path, "doge-identification/") # This will force tensorflow to run on the cpu os.environ["CUDA_VISIBLE_DEVICES"] = "-1" list_of_files = glob.glob(models_path + "*.h5") latest_model_path = max(list_of_files, key=os.path.getctime) path, newest_model = os.path.split(latest_model_path) print("Newest Model: ", newest_model) trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=data_path) metrics = trainer.evaluateModel( model_path=latest_model_path, json_path=os.path.join(execution_path, "doge-identification/json/detection_config.json"), iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5)
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory( data_directory="C:/Users/ABC/Desktop/New folder/TDAI/Data/hololens") trainer.evaluateModel( model_path="C:/Users/ABC/Desktop/New folder/TDAI/Data/hololens/models", json_path= "C:/Users/ABC/Desktop/New folder/TDAI/Data/hololens/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5)
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="../data/") metrics = trainer.evaluateModel( model_path="../models/detection_model-ex-015--loss-0004.540.h5", json_path="../json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5, ) print(metrics)
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="hololens") trainer.evaluateModel(model_path="hololens-ex-60--loss-2.76.h5", json_path="detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5) # download JSON file via https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/detection_config.json # download detection model via https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/hololens-ex-60--loss-2.76.h5 """ SAMPLE RESULT Model File: hololens_detection_model-ex-09--loss-4.01.h5 Using IoU : 0.5 Using Object Threshold : 0.3 Using Non-Maximum Suppression : 0.5 hololens: 0.9613 mAP: 0.9613 =============================== """
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="data/camembert") trainer.setTrainConfig(object_names_array=["camembert"], batch_size=4, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="ImageDataSet") trainer.setTrainConfig(object_names_array=["SwimmingPool"], batch_size=4, num_experiments=200, train_from_pretrained_model="yolov3.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer = DetectionModelTrainer() trainer.setDataDirectory(data_directory="headsets2") trainer.setTrainConfig(object_names_array=["surfer"], batch_size=4, num_experiments=5, train_from_pretrained_model= "/Users/hollands/dev/cfmodelserver/models/yolo-tiny.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="apple_dataset") trainer.setTrainConfig(object_names_array=["apple", "damaged_apple"], batch_size=8, num_experiments=50, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="characters") trainer.setTrainConfig(object_names_array=[ 'aeolianDune', 'beach', 'crevasseRiverBedLagDeposit', 'crevasseRiverChannelBar', 'distalBar', 'distributaryChannelFill', 'distributaryMouthBar', 'floodPlain', 'floodSwamp', 'interdistributaryEstuary', 'majorRiverBedLagDeposit', 'majorRiverChannelBar', 'meanderPointBar', 'mouthBar', 'proximalDeepseaFan', 'underwaterDistributaryChannel', 'underwaterNaturalLevee' ], batch_size=2, num_experiments=10, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel() metrics = trainer.evaluateModel( model_path="characters/models", json_path="characters/json/detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5) print(metrics)
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="qr") metrics = trainer.evaluateModel(model_path="detection_model-ex-001--loss-0000.000.h5", json_path="detection_config.json", iou_threshold=0.5, object_threshold=0.3, nms_threshold=0.5)
from imageai.Detection.Custom import DetectionModelTrainer names = ['on', 'off'] trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory='dataset') trainer.setTrainConfig(object_names_array=names, batch_size=4, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()