def train_model(): trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="examples/specjale") trainer.setTrainConfig(object_names_array=["specjal"], batch_size=4, num_experiments=10, train_from_pretrained_model="models/yolo.h5") trainer.trainModel()
def train_yolo(lst_y, train_path="fs/training_yolo/", transfer_modelfile=""): ## setup yolo = DetectionModelTrainer() yolo.setModelTypeAsYOLOv3() yolo.setDataDirectory(data_directory=train_path) yolo.setTrainConfig(object_names_array=lst_y, batch_size=4, num_experiments=1, train_from_pretrained_model=transfer_modelfile) ## train print("--- training ---") yolo.trainModel() ## evaluate print("--- metrics ---") metrics = yolo.evaluateModel(model_path=train_path + "models", json_path=train_path + "json/detection_config.json", iou_threshold=0.5, object_threshold=0.5, nms_threshold=0.5) print(metrics) ## laod model print("--- loading model ---") modelfile = os.listdir(train_path + "models/")[0] return load_yolo(modelfile=train_path + "models/" + modelfile, confjson=train_path + "/json/detection_config.json")
def train(self, data_dir, classes, batch_size, epochs): trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=data_dir) trainer.setTrainConfig(object_names_array=classes, batch_size=batch_size, num_experiments=epochs, train_from_pretrained_model=PRETRAINED_MODEL) trainer.trainModel()
def train(): trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="") trainer.setTrainConfig( object_names_array=["Container", "Dent", "Rust", "Crack"], batch_size=4, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5")
def entrenarModelo(): trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="2_RESPUESTA") trainer.setTrainConfig(object_names_array=["RESPUESTA"], batch_size=2, num_experiments=50, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
def train_detection_model(): from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="fire-dataset") trainer.setTrainConfig(object_names_array=["fire"], batch_size=8, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
class Trainer(): def __init__(self): self.trainer = DetectionModelTrainer() self.trainer.setModelTypeAsYOLOv3() # Set name of dataset directory self.trainer.setDataDirectory(data_directory="wheels_dataset") self.trainer.setTrainConfig(object_names_array=['wheelchair', 'pull trolley', 'push trolley'], batch_size=8, num_experiments=10, train_from_pretrained_model='wheels-yolov3.h5') def train(self): self.trainer.trainModel()
class Trainer(): def __init__(self): self.trainer = DetectionModelTrainer() self.trainer.setModelTypeAsYOLOv3() # Set name of dataset directory self.trainer.setDataDirectory(data_directory="dog_dataset") self.trainer.setTrainConfig(object_names_array=['dog'], batch_size=4, num_experiments=10, train_from_pretrained_model='yolov3-dogs.h5') def train(self): self.trainer.trainModel()
def trainer(): trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=data_directory) trainer.setTrainConfig( object_names_array=["seal", "no_seal"], batch_size=4, num_experiments=50, train_from_pretrained_model="pretrained-yolov3.h5", ) trainer.trainModel()
def train_detection_model(): from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="fire-dataset") trainer.setTrainConfig(object_names_array=["fire"], batch_size=8, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5") # download 'pretrained-yolov3.h5' from the link below # https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5 trainer.trainModel()
def train(): trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=os.path.join('drive','MyDrive','train_data', 'circle')) trainer.setTrainConfig( object_names_array=['circle'], batch_size=4, num_experiments=200, train_from_pretrained_model='pretrained-yolov3.h5' ) trainer.trainModel()
def trainer( data_directory="plates", object_names_array=["LP"], batch_size=4, num_experiments=2, train_from_pretrained_model="plates/models/detection_model-ex-002--loss-0007.222.h5" ): trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory) trainer.setTrainConfig(object_names_array, batch_size, num_experiments, train_from_pretrained_model) trainer.trainModel()
def test_detection_training(clear_keras_session): trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=sample_dataset) trainer.setTrainConfig(object_names_array=["hololens"], batch_size=2, num_experiments=1, train_from_pretrained_model=pretrained_model) trainer.trainModel() assert os.path.isdir(sample_dataset_json_folder) assert os.path.isdir(sample_dataset_models_folder) assert os.path.isdir(sample_dataset_cache_folder) assert os.path.isfile(os.path.join(sample_dataset_json_folder, "detection_config.json")) shutil.rmtree(os.path.join(sample_dataset_json_folder)) shutil.rmtree(os.path.join(sample_dataset_models_folder)) shutil.rmtree(os.path.join(sample_dataset_cache_folder))
def keurmerk_train(data, model): """Trains YOLOv3 model from pretrained model. Arguments: data {string} -- Directory where the image and annotation data is stored according to the specified structure. model {string} -- Directory where the chosen model is stored. """ # Set model type trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() labels = [ "fairtrade", "planetproof", "utz", "organic", "vegan", "weidemelk", "bio", "eko", "asc", "msc", "ebio", "beterleven", ] # Data folder trainer.setDataDirectory(data_directory=DATA_DIR) # Training configuration trainer.setTrainConfig( object_names_array=labels, batch_size=4, num_experiments=100, train_from_pretrained_model=MODEL_PATH, ) trainer.trainModel()
def train_model(self, data_dir, user, objs_array, model=None, new_model=False): """ Train a specific model according with a set of data Args: data_dir (str): directory with the YOLO training data (pictures and annotations) user (str): registered user which the model belongs objs_array (list): list containing the names of unique objects to be trained for model (str): full path of the model file to be loaded new_model (bool): True if after training a new model file will be generated Returns: object: trained model """ if new_model: model_path = '' else: self.load_model(user=user, model_path=model) model_path = self.model_path model_trainer = DetectionModelTrainer() model_trainer.setModelTypeAsYOLOv3() model_trainer.setDataDirectory(data_directory=data_dir) model_trainer.setTrainConfig(object_names_array=list(set(objs_array)), batch_size=4, num_experiments=200, train_from_pretrained_model=model_path) model_trainer.trainModel() if new_model: self.version_model(user=user) self.model = model_trainer return self.model
def train_model(self, model_pretrained, label_list, batch_size=2, epoch=10, use_pretrained_model=False): self.__use_pretrained_model = use_pretrained_model if self.__use_pretrained_model: trainer = DetectionModelTrainer() # fixe le type du model comme etant yoloV3 trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(self.__data_dir) trainer.setTrainConfig( object_names_array=label_list, batch_size=batch_size, num_experiments=epoch, train_from_pretrained_model=model_pretrained) trainer.trainModel()
def main(): # Will we train? if DOTRAIN: # Use last trained model as base for transferlearning? last_model = '' # Ohmy. This means None. if DOTRANSFERLEARN: last_model = MODEL_PATH if DORESUMELAST: last_model = get_last_model() else: if os.path.exists(os.path.join(DATA_PATH, 'cache')): shutil.rmtree(os.path.join(DATA_PATH, 'cache')) shutil.rmtree(os.path.join(DATA_PATH, 'json')) shutil.rmtree(os.path.join(DATA_PATH, 'logs')) shutil.rmtree(os.path.join(DATA_PATH, 'models')) trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=DATA_PATH) trainer.setTrainConfig(object_names_array=OBJECT_NAMES, batch_size=BATCHCOUNT, num_experiments=EXPIREMENTSCOUNT, train_from_pretrained_model=last_model) trainer.trainModel() # Will we evaluate? if DOEVALUATE: # Show evaluations for the last model metrics = trainer.evaluateModel(model_path=get_last_model(), json_path=os.path.join( DATA_PATH, 'json', 'detection_config.json'), iou_threshold=.5, object_threshold=.3, nms_threshold=.5) print(metrics)
def main(): if (len(sys.argv) < 3): print("Usage: " + sys.argv[0] + " <dataset_dir> <pre_trained_model>") exit(-1) dataset_dir = sys.argv[1] pre_trained_model = sys.argv[2] if (len(sys.argv) > 2): image_name = sys.argv[2] else: print("Enter image or directory name: ") image_name = input() trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=dataset_dir) trainer.setTrainConfig(object_names_array=[ "Ripe Strawberry", "Green Strawberry", "Bad Strawberry" ], batch_size=4, num_experiments=40, train_from_pretrained_model=pre_trained_model) trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="bottles") trainer.setTrainConfig( object_names_array=["PET", "HDPE(1)", "HDPE(2)", "PVC", "Opaque", "PP"], batch_size=2, num_experiments=200, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="ship") # trainer.setTrainConfig(object_names_array=["hololens"], batch_size=4, num_experiments=200, train_from_pretrained_model="pretrained-yolov3.h5") trainer.setTrainConfig(object_names_array=["ship"], batch_size=4, num_experiments=200, train_from_pretrained_model="pretrained-yolov3.h5") # In the above,when training for detecting multiple objects, #set object_names_array=["object1", "object2", "object3",..."objectz"] trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() # others can include RetinaNet trainer.setDataDirectory(data_directory="inputs/hololens") trainer.setTrainConfig( object_names_array=["hololens" ], # an array of names of all objects in your dataset batch_size=4, num_experiments=100, train_from_pretrained_model="models/pretrained-yolov3.h5" ) # use transfer learning from a pretrained YOLO model trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer import os file = "Buildings" trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="Training Data\\" + file + "\\") trainer.setTrainConfig(object_names_array=["building"], batch_size=1, num_experiments=197, train_from_pretrained_model="model\\yolo_trained.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer import os execution_path = os.getcwd() trainer = DetectionModelTrainer() trainer.setGpuUsage(1) trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=".") trainer.setTrainConfig(object_names_array=["empty coffee", "not empty coffee"], batch_size=4, num_experiments=10, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
# import os # img = os.listdir("validation/images") # for i in range(len(img)): # img[i] = img[i].split(".")[0] + ".xml" # # ann = os.listdir("validation/annotations") # for i in img: # if i not in ann: # print(i.split(".")[0] + ".jpg") # os.remove(i.split(".")[0] + ".jpg") from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=".") trainer.setTrainConfig(object_names_array=["coke"], num_experiments=20, train_from_pretrained_model="pretrained-yolov3.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="Pothole") trainer.setTrainConfig( object_names_array=[ "Pothole Severity Low", "Pothole Severity High", "Pothole Severity Medium" ], batch_size=4, num_experiments=30, train_from_pretrained_model="pretrained-yolov3.h5" ) #download pre-trained model via https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5 trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="Strawberries") trainer.setTrainConfig( object_names_array=["red strawberry", "green strawberry"], batch_size=4, num_experiments=1, train_from_pretrained_model="pretrained-yolov3.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="apple_dataset\models\pretrained-yolov3.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory=r"G:\RYD\DataSet\new") trainer.setTrainConfig( object_names_array=["question"], batch_size=4, num_experiments=100, train_from_pretrained_model=r"G:\ryd\yolo\pretrained-yolov3.h5") trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer obj = 'tag' HOME = '/home/weihao/Projects' trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() trainer.setDataDirectory(data_directory="{}/{}".format(HOME, obj)) trainer.setTrainConfig( object_names_array=[obj], batch_size=4, num_experiments=10, train_from_pretrained_model="{}/pretrained-yolov3.h5".format(HOME)) trainer.trainModel()
from imageai.Detection.Custom import DetectionModelTrainer trainer = DetectionModelTrainer() trainer.setModelTypeAsYOLOv3() data_dir = "./data/images/box/" #model_dir = "./data/models/pretrained-yolov3.h5" #model_dir = "./data/models/pretrained-yolov3.h5" model_dir = f"./data/images/box/best_model/detection_model.h5" trainer.setDataDirectory(data_directory=data_dir) trainer.setTrainConfig(object_names_array=['true'], batch_size=8, num_experiments=100, train_from_pretrained_model=model_dir) trainer.trainModel()