def fit2(): print("fit2") model = Model([ nn.Dense(128, inshape=1, activation='relu'), nn.Dense(256, activation='relu'), nn.Dropout(0.80), nn.Dense(1) ]) model.assemble() sess = Session( model, loss=losses.Mse(), optimizer=optimizers.Fixed(), ) history = sess.fit(ds, 200000, val_data=val_ds, val_epochs=1000, listeners=[ FitListener('val_end', callback=lambda h: on_val_end(sess, h)) ]) fit_report(history, report_path + '02.png', 15)
def fit(name, optimizer): inshape = ds_train.data.shape[1:] #pdb.set_trace() model = Model([ cnn.Conv2D(32, (3, 3), inshape=inshape), cnn.MaxPool2D((2, 2), strides=(2, 2)), cnn.Conv2D(64, (3, 3)), cnn.MaxPool2D((2, 2), strides=(2, 2)), cnn.Conv2D(64, (3, 3)), nn.Flatten(), nn.Dense(64), nn.Dropout(0.5), nn.Dense(10) ]) model.assemble() sess = Session(model, loss=losses.CategoricalCrossentropy(), optimizer=optimizer) stop_fit = session.condition_callback(lambda: sess.stop_fit(), 'val_loss', 30) accuracy = lambda h: fit_tools.accuracy(sess, ds_test, h) def save_and_report(history): #pdb.set_trace() fit_tools.fit_report(history, report_path + name + ".png") model.save(model_path + name) #pdb.set_trace() history = sess.fit(ds_train, 200, val_data=ds_test, val_steps=100, listeners=[ stop_fit, session.FitListener('val_end', callback=accuracy), session.FitListener('val_end', callback=save_and_report) ]) save_and_report(history)
def fit(name, model): sess = Session(model, loss = losses.SparseCategoricalCrossentropy(), optimizer = optimizers.Adam() ) stop_fit = session.condition_callback(lambda :sess.stop_fit(), 'loss', 100) def save_and_report(history): #pdb.set_trace() fit_tools.fit_report(history, report_path+name+".png") model.save(model_path+name) #pdb.set_trace() history = sess.fit(ds_train, 1000, listeners=[ stop_fit, session.FitListener('epoch_end', callback=save_and_report) ] ) save_and_report(history)
def fit(name, model): sess = Session(model, loss = losses.BinaryCrossentropy(), optimizer = optimizers.Adam() ) stop_fit = session.condition_callback(lambda :sess.stop_fit(), 'val_loss', 10) def save_and_report(history): #pdb.set_trace() fit_tools.fit_report(history, report_path+name+".png") model.save(model_path+name) #pdb.set_trace() history = sess.fit(ds_train, 100, val_data=ds_test, val_batches=20, listeners=[ stop_fit, session.FitListener('val_end', callback=fit_tools.binary_accuracy), session.FitListener('epoch_end', callback=save_and_report) ] ) save_and_report(history)
def fit(): inshape = ds_train.data.shape[1] model = Model([nn.Dense(10, inshape=inshape, activation='relu')]) model.assemble() sess = Session(model, loss=losses.CategoricalCrossentropy(), optimizer=optimizers.Fixed(0.001)) stop_fit = session.condition_callback(lambda: sess.stop_fit(), 'val_loss', 10) #pdb.set_trace() history = sess.fit(ds_train, 20000, val_epochs=5, val_data=ds_test, listeners=[ stop_fit, session.FitListener('val_end', callback=accuracy) ]) fit_report(history, report_path + "0.png")