Example #1
0
var_unet = Model(inputs, outputs)
var_unet.summary()

#[Keras Optimizer, Loss & Metrics]  ------------------------------------------
optimizer = {
    "optimizer" : keras.optimizers.Adam(lr=1e-3),
    "loss"      : ezlosses.vae_loss(z_mean,z_log_var,train.X.shape[1:]),
    # "metrics"   : [ezlosses.reconstruction_loss]
}

# # [EZMODEL]  ------------------------------------------------------------------
ez = ezmodel(
    train = train,
    test  = test,
    network = var_unet,
    optimizer = optimizer,
    transformers = transformers
)
# # # Training --------------------------------------------------------------------
parameters = {
    "epochs" : 40,
    # "validation_split": 0.2
}
ez.train(parameters)



p = ez.predict()
r = show_images(p,4)
Example #2
0
import sys, os
sys.path.append(os.path.abspath('..\\..\\ezmodel'))

from ezmodel.ezmodel import ezmodel
from ezmodel.ezdata import ezdata
from ezmodel.eztrainer import eztrainer
# [EZ MODEL initialization]
ez_model = ezmodel(type="classification")
print(ez_model.type)

# ----------------------------  [EZ Data]  -----------------------------------
# Table Classification from a csv file:
# - One subdirectory by Class
parameters = {
    "name": "Bacteria CSV",
    "path": "C:\\Users\\daian\\Desktop\\DATA\\bacteria_csv\\bacteria.csv",
    "table.target.column": "Label",
}

ez_data = ezdata(parameters)

ez_data.gen_test(size=0.2)

ez_data.preprocess(X="standard",
                   y="categorical")  #on crée les scaler dans ez_data aussi

# --------------------------  [EZ Trainer] ------------------------------------
ez_trainer = eztrainer()

ez_trainer.gen_trainval(ez_data, size=0.2)
Example #3
0
def load_ezmodel(filename):
    if not os.path.isfile(filename + ".zip"):
        raise Exception("[Fail] ezmodel(load) : ", filename,
                        ".zip has not been found !")

    ez = ezmodel(empty=True)

    zip_ref = ZipFile(filename + ".zip", 'r')
    zip_ref.extractall(".")
    zip_ref.close()

    filehandler = open(filename + ".data.pkl", 'rb')
    tmp = pickle.load(filehandler)
    filehandler.close()
    ez.data_train = tmp[0]
    ez.data_test = tmp[1]

    filehandler = open(filename + ".trans.pkl", 'rb')
    tmp = pickle.load(filehandler)
    filehandler.close()
    ez.transformerX = tmp[0]
    ez.transformerY = tmp[1]

    filehandler = open(filename + ".params.pkl", 'rb')
    tmp = pickle.load(filehandler)
    filehandler.close()
    ez.model_parameters = tmp

    filehandler = open(filename + ".hist.pkl", 'rb')
    tmp = pickle.load(filehandler)
    filehandler.close()
    ez.history = tmp

    filehandler = open(filename + ".aug.pkl", 'rb')
    tmp = pickle.load(filehandler)
    filehandler.close()
    ez.augmentation = tmp

    #Network + optimizer + custom losses
    import ezmodel.ezlosses as tmp
    import types
    l = [
        getattr(tmp, a) for a in dir(tmp)
        if isinstance(getattr(tmp, a), types.FunctionType)
    ]
    values = l
    keys = []
    for i in l:
        keys.append((i.__name__))
    custom_objects = dict(zip(keys, values))
    ez.network = load_model(filename + ".h5", custom_objects=custom_objects)

    os.remove(filename + ".h5")
    os.remove(filename + ".data.pkl")
    os.remove(filename + ".trans.pkl")
    os.remove(filename + ".params.pkl")
    os.remove(filename + ".hist.pkl")
    os.remove(filename + ".aug.pkl")

    print("[X]Ezmodel loaded successfully !")

    return ez
Example #4
0
import sys, os
sys.path.append(os.path.abspath('..\\..\\ezmodel'))

from ezmodel.ezmodel   import ezmodel
from ezmodel.ezdata    import ezdata
from ezmodel.eztrainer import eztrainer

# [EZ MODEL loading]
ez_model = ezmodel(load = "model0")

print("Model parameters = ",ez_model.model_parameters)

# [EZ evaluation]
ez_model.evaluate()
optimizer = {
    "optimizer": keras.optimizers.Adam(lr=1e-4),
    "loss": keras.losses.categorical_crossentropy,
    "metrics": [keras.metrics.categorical_accuracy]
}
# [EZMODEL]  ------------------------------------------------------------------
augmentation_parameters = {
    "rotation_range": 15,
    "width_shift_range": .15,
    "height_shift_range": .15,
    "horizontal_flip": True
}

ez = ezmodel(train=train,
             test=test,
             network=net,
             optimizer=optimizer,
             transformers=transformers,
             augmentation=augmentation_parameters)

# Training --------------------------------------------------------------------
parameters = {
    "epochs": 200,
    # "validation_split": 0.2
}
ez.train(parameters)
# Evaluation ------------------------------------------------------------------
ez.evaluate()

# Evaluation already defined augmentation for Test Time Augmentation (TTA)
ez.evaluate(tta=10)
Example #6
0
# sys.exit()

# # [EZNETWORK]  ----------------------------------------------------------------
from ezmodel.eznetwork import LeNet5
net = LeNet5(input=train)
net.summary()

# [Keras Optimizer, Loss & Metrics]  ------------------------------------------
optimizer = {
    "optimizer": keras.optimizers.Adam(lr=1e-4),
    "loss": keras.losses.categorical_crossentropy,
    "metrics": [keras.metrics.categorical_accuracy]
}

# net.compile(**optimizer)
# [EZMODEL]  ------------------------------------------------------------------
ez = ezmodel(train=train, test=test, network=net, optimizer=optimizer)

# Training --------------------------------------------------------------------
parameters = {
    "epochs": 50,
}
ez.train(parameters)

# Evaluation ------------------------------------------------------------------
#ez.evaluate()
# p = ez.network.predict_generator(ez.data_test.generator,steps=ez.data_test.generator.n//ez.data_test.generator.batch_size)
# print(p.argmax(axis=1))
# p=net.predict_generator(test_gen,steps=test_gen.n//test_gen.batch_size)
# print(p)