def train_traffic_net():
    download_traffic_net()

    trainer = ModelTraining()
    trainer.setModelTypeAsResNet()
    trainer.setDataDirectory("trafficnet_dataset_v1")
    trainer.trainModel(num_objects=4, num_experiments=200, batch_size=32, save_full_model=True, enhance_data=True)
def main():
    model_trainer = ModelTraining()
    model_trainer.setModelTypeAsResNet()
    model_trainer.setDataDirectory("data/images")
    model_trainer.trainModel(num_objects=2,
                             num_experiments=20,
                             enhance_data=True,
                             batch_size=16,
                             show_network_summary=True)
Exemple #3
0
def main(path_data):
    model_trainer = ModelTraining()
    model_trainer.setModelTypeAsResNet()
    model_trainer.setDataDirectory(path_data)
    model_trainer.trainModel(num_objects=10,
                             num_experiments=20,
                             enhance_data=True,
                             batch_size=32,
                             show_network_summary=True)
Exemple #4
0
def ImageREcognition():
    model_trainer = ModelTraining()
    model_trainer.setModelTypeAsResNet()
    model_trainer.setDataDirectory("idenprof")
    model_trainer.trainModel(num_objects=10,
                             num_experiments=100,
                             enhance_data=True,
                             batch_size=32,
                             show_network_summary=True)
Exemple #5
0
def training(image_directory):
    model_trainer = ModelTraining()
    model_trainer.setModelTypeAsResNet()
    model_trainer.setDataDirectory(training_image_directory)
    model_trainer.trainModel(num_objects=1,
                             num_experiments=200,
                             enhance_data=True,
                             batch_size=5,
                             show_network_summary=True)
Exemple #6
0
def train_func(n):

    model_trainer = ModelTraining()
    model_trainer.setModelTypeAsResNet()
    model_trainer.setDataDirectory('Dataset')
    model_trainer.trainModel(num_objects=n,
                             num_experiments=100,
                             enhance_data=True,
                             batch_size=32,
                             show_network_summary=True)
Exemple #7
0
def modelIrain(dataDir='data', classNum=2, epochs=100, batch_size=32):
    '''
    模型训练部分
    '''
    #创建了ModelTraining类的新实例
    model_trainer = ModelTraining()
    #将模型类型设置为ResNet
    model_trainer.setModelTypeAsResNet()
    #设置我们想要训练的数据集的路径
    model_trainer.setDataDirectory(dataDir)
    #模型训练
    '''
    num_objects:该参数用于指定图像数据集中对象的数量
    num_experiments:该参数用于指定将对图像训练的次数,也称为epochs
    enhance_data(可选):该参数用于指定是否生成训练图像的副本以获得更好的性能
    batch_size:该参数用于指定批次数量。由于内存限制,需要分批训练,直到所有批次训练集都完成为止。
    show_network_summary:该参数用于指定是否在控制台中显示训练的过程
    '''
    model_trainer.trainModel(num_objects=classNum,
                             num_experiments=epochs,
                             enhance_data=True,
                             batch_size=batch_size,
                             show_network_summary=True)
    print('Model Train Finished!!!')

    def modelPredict(model_path='data/models/model_ex-001_acc-0.500000.h5',
                     class_path='data/json/model_class.json',
                     pic_path='a.jpg',
                     classNum=2,
                     resNum=5):
        '''

        模型预测部分
        prediction_speed[模型加载的速度]:fast faster fastest
        '''
        prediction = CustomImagePrediction()
        prediction.setModelTypeAsResNet()
        prediction.setModelPath(model_path)
        prediction.setJsonPath(class_path)
        prediction.loadModel(num_objects=classNum, prediction_speed='fastest')
        prediction, probabilities = prediction.predictImage(
            pic_path, result_count=resNum)
        for eachPrediction, eachProbability in zip(predictions, probabilities):
            print(eachPrediction + " : " + str(eachProbability))

    if __name__ == '__main__':
        #模型训练
        modelTrain(dataDir='data', classNum=2, epochs=10, batch_size=8)
        #模型识别预测
        modelPredict(model_path='data/models/model_ex-001_acc-0.500000.h5',
                     class_path='data/json/model_class.json',
                     pic_path='test.jpg',
                     classNum=2,
                     resNum=5)
 def train_model(foldername,Model_Type,num_objects=2, num_experiments=1, enhance_data=False, batch_size=1, show_network_summary=True):
     model_trainer = ModelTraining()
     if Model_Type in "ResNet":
         model_trainer.setModelTypeAsResNet()
     elif Model_Type in "SqueezeNet":
         model_trainer.setModelTypeAsSqueezeNet()
     elif Model_Type in "InceptionV3":
         model_trainer.setModelTypeAsInceptionV3()
     elif Model_Type in "DenseNet":
         model_trainer.setModelTypeAsDenseNet()
     model_trainer.setDataDirectory(foldername)
     model_trainer.trainModel(num_objects=num_objects, num_experiments=num_experiments, enhance_data=enhance_data, batch_size=batch_size, show_network_summary=show_network_summary)
def test_inception_v3_training():

    trainer = ModelTraining()
    trainer.setModelTypeAsInceptionV3()
    trainer.setDataDirectory(data_directory=sample_dataset)
    trainer.trainModel(num_objects=10,
                       num_experiments=1,
                       enhance_data=True,
                       batch_size=4,
                       show_network_summary=True)

    assert os.path.isdir(sample_dataset_json_folder)
    assert os.path.isdir(sample_dataset_models_folder)
    assert os.path.isfile(
        os.path.join(sample_dataset_json_folder, "model_class.json"))
    assert (len(os.listdir(sample_dataset_models_folder)) > 0)
    shutil.rmtree(os.path.join(sample_dataset_json_folder))
    shutil.rmtree(os.path.join(sample_dataset_models_folder))
Exemple #10
0
def TrainModel(files, Classes, Epochs, BatchSize):
    model_trainer = ModelTraining()  #create an instance for de model training
    model_trainer.setModelTypeAsResNet(
    )  #set model to ResNet NN (SqueezeNet, ResNet, InceptionV3 and DenseNet)
    model_trainer.setDataDirectory(
        files)  #folder that contains train and test sets
    '''
    train model function
    number_objects : number of clases
    num_experiments : number of iterations (epochs)
    Enhance_data (Optional) : if true, creates modified copies of the images to maximize accuracy (but more process cost)
    batch_size: number of images that the model trainer will study at once
    Show_network_summary (Optional) : if true, shows the structure of the model type
    '''
    model_trainer.trainModel(num_objects=Classes,
                             num_experiments=Epochs,
                             enhance_data=True,
                             batch_size=BatchSize,
                             show_network_summary=True)
Exemple #11
0
 def train(
     self,
     epochs=100,
     enhance_data=True,
     batch_size=16,
     show_network_summary=True,
 ):
     click.echo("Start training...")
     # Instantiate a ModelTraining object that will be used for model training
     trainer = ModelTraining()
     # Set the model type of the neural network (it must be the same of the
     # prediction)
     self._set_proper_model_type(self.model_type, trainer)
     # Set the path to the data directory
     trainer.setDataDirectory(
         os.path.join(self.base_path, self.dataset_name))
     # Train the model
     trainer.trainModel(
         num_objects=self.class_number,
         num_experiments=epochs,
         enhance_data=enhance_data,
         batch_size=batch_size,
         show_network_summary=show_network_summary,
     )
from imageai.Prediction.Custom import ModelTraining

model_trainer = ModelTraining()
model_trainer.setModelTypeAsResNet()
model_trainer.setDataDirectory(r"D:/python/imageAI_model_train/pets")
model_trainer.trainModel(num_objects=2,
                         num_experiments=100,
                         enhance_data=True,
                         batch_size=16,
                         show_network_summary=True)
from imageai.Prediction.Custom import ModelTraining

model_trainer = ModelTraining(
)  # type of training algorithm in this case basic NN
model_trainer.setModelTypeAsResNet(
)  # defines the type of model that will be stored, in this case it will be a simple .h5 file
model_trainer.setDataDirectory(
    "idenprof")  # where the AI will look for data to train it
model_trainer.trainModel(num_objects=2,
                         num_experiments=200,
                         batch_size=32,
                         show_network_summary=True)
# num_objects is the total number of different types of objects, eg: chef, car, cat
# num_experiments is the total number of epochs or the total number of times an "experiment" is run
# batch_size is the total number of images tested in an epoch
from imageai.Prediction.Custom import ModelTraining

model_trainer = ModelTraining(
)  ##create an instance of the ModelTraining class

model_trainer.setModelTypeAsResNet(
)  ##set your instance property and start the traning process.
##this function sets the model type of the training instance you created to the ResNet
##model, which means the ResNet algorithm will be trained on your dataset

model_trainer.setDataDirectory(
    r"C:\Users\Andreas Thoma\Desktop\Mathimata\EPL445\Project\Tortillas")
## accepts a string which must be the path to the folder that contains the test and train subfolder of your image dataset

model_trainer.trainModel(num_objects=2,
                         num_experiments=5,
                         enhance_data=True,
                         batch_size=32,
                         show_network_summary=True)
##this is the function that starts the training process. Once it starts, it will create a JSON file in
##the dataset/json folder (e.g Tortillas/json) which contains the mapping of the classes of the dataset.
##The JSON file will be used during custom prediction to produce reults