def main(_): loader = Loader(flag="azenuz_small") config = Config(loader, flag="azenuz_small") config.gpu = 0 if platform.system() == 'Linux': gpuid = config.gpu os.environ["CUDA_VISIBLE_DEVICES"] = '{}'.format(gpuid) device = '/gpu:' + str(gpuid) else: device = '/cpu:0' i = 0 graph = tf.Graph() with graph.as_default(): trainm = CTR_ggnn(config, device, loader, "Train") testm = CTR_ggnn(config, device, loader, "Valid") session_config = tf.ConfigProto(allow_soft_placement=True, log_device_placement=False) session_config.gpu_options.allow_growth = True with tf.Session(graph=graph, config=session_config) as session: # session.run(tf.global_variables_initializer()) CTR_GNN_loader(session, config) best_auc = 0. best_epoch = 0 auc = 0. for epoch in range(config.epoch_num): # cost, auc = run(session, config, trainm, loader, verbose=True) # INFO_LOG("Epoch %d Train AUC %.3f" % (epoch + 1, auc)) # INFO_LOG("Epoch %d Train costs %.3f" % # (epoch, cost)) session.run(tf.local_variables_initializer()) cost, auc = run(session, config, testm, loader, verbose=True) INFO_LOG("Epoch %d Valid AUC %.3f" % (epoch, auc)) INFO_LOG("Epoch %d Valid cost %.3f" % (epoch, cost)) # # if best_auc < auc: best_auc = auc best_epoch = epoch # CTR_GNN_saver(session, config, best_auc, best_epoch) INFO_LOG("*** best AUC now is %.3f in %d epoch" % (best_auc, best_epoch))
def main(_): loader = Loader(flag="azenuz_small") config = Config(loader, flag="azenuz_small") config.gpu = 1 if platform.system() == 'Linux': gpuid = config.gpu os.environ["CUDA_VISIBLE_DEVICES"] = '{}'.format(gpuid) device = '/gpu:' + str(gpuid) else: device = '/cpu:0' lr_updater = LearningRateUpdater(config.learning_rate, config.decay, config.decay_epoch) i = 0 graph = tf.Graph() with graph.as_default(): trainm = CTR_ggnn(config, device, loader, "Train") testm = CTR_ggnn(config, device, loader, "Valid") session_config = tf.ConfigProto(allow_soft_placement=True, log_device_placement=False) session_config.gpu_options.allow_growth = True with tf.Session(graph=graph, config=session_config) as session: # session.run(tf.global_variables_initializer()) CTR_GNN_loader(session, config) best_auc = 0. best_logloss = 1. best_epoch_auc = 0. best_epoch_logloss = 0. auc = 0. for epoch in range(config.epoch_num): trainm.update_lr(session, lr_updater.get_lr()) cost, auc = run(session, config, trainm, loader, verbose=True) INFO_LOG("Epoch %d Train AUC %.3f" % (epoch + 1, auc)) INFO_LOG("Epoch %d Train costs %.3f" % (epoch, cost)) session.run(tf.local_variables_initializer()) cost, auc = run(session, config, testm, loader, verbose=True) INFO_LOG("Epoch %d Valid AUC %.3f" % (epoch, auc)) INFO_LOG("Epoch %d Valid cost %.3f" % (epoch, cost)) # # lr_updater.update(auc, epoch) if best_auc < auc: best_auc = auc best_epoch_auc = epoch CTR_GNN_saver(session, config, best_auc, best_epoch_auc) if best_logloss > cost: best_logloss = cost best_epoch_logloss = epoch # CTR_GNN_saver(session, config, best_epoch_logloss, best_epoch_logloss) INFO_LOG("*** best AUC now is %.3f in %d epoch" % (best_auc, best_epoch_auc)) INFO_LOG("*** best logloss now is %.3f in %d epoch" % (best_logloss, best_epoch_logloss)) if epoch % 300 == 0 and epoch != 0: loader.change_data_list(loader.increase_data_idx())