Ejemplo n.º 1
0
def main():
    # This main will first load the datasets then start the training for both, age as well as gender estimation
    # with the default amount of epochs with the value 312 and an early stopping callback with the patience of 4.
    # You can change the amount of epochs by typing "epochs = X" into the Trainer constructor.
    # If you want to train a model by loading the weights of an allready trained model,
    # use the load_model method from the OurModel class.

    # After the training is done, the models will be saved and evulation files (.csv) will be created.
    # Use the parsers to interpret the .csv files

    dataset = Dataset()

    dataset.createFolder("../data/classification")
    dataset.createClassificationFolders("../data/classification/age/Train")
    dataset.createClassificationFolders("../data/classification/age/Valid")
    dataset.createClassificationFolders("../data/classification/age/Test")

    #FGNET
    dataset.downloadAndUnzip("http://yanweifu.github.io/FG_NET_data/FGNET.zip",
                             "../data/FGNET.zip", "../data/FGNET")
    dataset.readAndPrintDataImagesFGNET("../data/FGNET",
                                        "../data/classification/age")

    # Start training for age estimation
    AgeModel = OurModel(0)
    AgeModel = Trainer(AgeModel.model,
                       filepath_age + "Train",
                       filepath_age + "Valid",
                       filepath_age + "Test",
                       identifier=0)
    AgeModel.train()
Ejemplo n.º 2
0
def main():
    # This main will first load the datasets then start the training for both, age as well as gender estimation
    # with the default amount of epochs with the value 312 and an early stopping callback with the patience of 4.
    # You can change the amount of epochs by typing "epochs = X" into the Trainer constructor.
    # If you want to train a model by loading the weights of an allready trained model,
    # use the load_model method from the OurModel class.

    # After the training is done, the models will be saved and evulation files (.csv) will be created.
    # Use the parsers to interpret the .csv files

    dataset = Dataset()

    dataset.createFolder("../data/classification")
    dataset.createClassificationFolders("../data/classification/age/Train")
    dataset.createClassificationFolders("../data/classification/age/Valid")
    dataset.createClassificationFolders("../data/classification/age/Test")
    #LAP
    dataset.downloadAndUnzip(
        "http://158.109.8.102/AppaRealAge/appa-real-release.zip",
        "../data/appa-real-release.zip", "../data/appa-real-release")
    dataset.readAndPrintDataImagesLAP("../data/appa-real-release", "train",
                                      "../data/classification/age/Train")
    dataset.readAndPrintDataImagesLAP("../data/appa-real-release", "valid",
                                      "../data/classification/age/Valid")
    dataset.readAndPrintDataImagesLAP("../data/appa-real-release", "test",
                                      "../data/classification/age/Test")
    #FGNET
    dataset.downloadAndUnzip("http://yanweifu.github.io/FG_NET_data/FGNET.zip",
                             "../data/FGNET.zip", "../data/FGNET")
    dataset.readAndPrintDataImagesFGNET("../data/FGNET",
                                        "../data/classification/age")
    #IMDB
    dataset.downloadAndUnpack(
        "https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/static/imdb"
        "_crop.tar", "../data/imdb_crop.tar", "../data/imdb_crop")
    dataset.readAndPrintDataImagesIMDB('../data/imdb_metadata.csv',
                                       "../data/imdb_crop",
                                       "../data/classification")

    # Start training for age estimation
    AgeModel = OurModel(0)
    AgeModel = Trainer(AgeModel.model,
                       filepath_age + "Train",
                       filepath_age + "Valid",
                       filepath_age + "Test",
                       identifier=0)
    AgeModel.train()

    # Start training for gender estimation
    GenderModel = OurModel(1)
    GenderModel = Trainer(GenderModel.model,
                          filepath_gender + "Train",
                          filepath_gender + "Valid",
                          filepath_gender + "Test",
                          identifier=1)
    GenderModel.train()
Ejemplo n.º 3
0
 def test_model_layers_allTrainable(self):
     with self.test_session():
         GenderModel = OurModel(1)
         trainable = True
         for layer in GenderModel.model.layers:
             if layer.trainable != True:
                 trainable = False
         AgeModel = OurModel(0)
         for layer in AgeModel.model.layers:
             if layer.trainable != True:
                 trainable = False
         self.assertEqual(trainable, True)
Ejemplo n.º 4
0
 def test_Agemodel_layerLength(self):
     with self.test_session():
         AgeModel = OurModel(0)
         length = 0
         for layer in AgeModel.model.layers:
             length = length + 1
         self.assertEqual(length, 24)
Ejemplo n.º 5
0
 def test_Gendermodel_layerLength(self):
     with self.test_session():
         GenderModel = OurModel(1)
         GenderModel.model.summary()
         length = 0
         for layer in GenderModel.model.layers:
             length = length + 1
         self.assertEqual(length, 24)
Ejemplo n.º 6
0
 def test_model_get_saved(self):
     with self.test_session():
         model = OurModel(0)
         trainer = Trainer(model.model,
                           filepath + "Train",
                           filepath + "Valid",
                           filepath + "Test",
                           identifier=0,
                           epochs=1,
                           save_model=True)
         trainer.train()
         self.assertEqual(True, os.path.exists(trainer.saved_model_path))
Ejemplo n.º 7
0
 def test_model_get_saved_and_loaded_correctly(self):
     with self.test_session():
         model = OurModel(0)
         trainer = Trainer(model.model,
                           filepath + "Valid",
                           filepath + "Valid",
                           filepath + "Valid",
                           identifier=0,
                           epochs=1,
                           save_model=True)
         trainer.train()
         model_load = OurModel(0)
         model_load.load_model(trainer.saved_model_path, 0)
         a = trainer.model.get_weights()
         b = model_load.model.get_weights()
         equal = True
         while len(a) != 0:
             c = a.pop()
             d = b.pop()
             if (c != d).any():
                 equal = False
         self.assertEqual(True, equal)
Ejemplo n.º 8
0
 def test_one_training_step(self):
     with self.test_session():
         model = OurModel(0)
         a = model.model.get_weights()
         trainer = Trainer(model.model,
                           filepath + "Train",
                           filepath + "Valid",
                           filepath + "Test",
                           identifier=0,
                           epochs=1,
                           save_model=False)
         trainer = trainer.train()
         b = trainer.get_weights()
         same = True
         while len(a) != 0:
             c = a.pop()
             d = b.pop()
             if (c != d).any():
                 same = False
         self.assertEqual(False, same)