def visualize(sess, config, args): from tensorflow.python import debug as tf_debug from kgcn.visualization import cal_feature_IG # 入力は1分子づつ batch_size = 1 # 入力データから、全データの情報, 学習用データの情報, 検証用データの情報, および # グラフに関する情報を順に取得する all_data, info = load_data(config, filename=config["dataset"], prohibit_shuffle=True) #all_data.labels = tf.one_hot(tf.cast(tf.squeeze(all_data.labels), tf.int32), depth=2) model = importlib.import_module(config["model.py"]) placeholders = model.build_placeholders(info, config, batch_size=batch_size) try: _model, prediction, _, _, _ = model.build_model( placeholders, info, config, batch_size=batch_size, feed_embedded_layer=True) except: _model, prediction, _, _, _ = model.build_model(placeholders, info, config, batch_size=batch_size) #--- セッションの初期化 saver = tf.train.Saver() print("[LOAD]", config["load_model"]) saver.restore(sess, config["load_model"]) #--- integrated gradientsの計算 cal_feature_IG(sess, all_data, placeholders, info, prediction, args.ig_modal_target, args.ig_label_target, logger=tf.logging, model=_model)
def visualize(sess, config, args): from kgcn.visualization import cal_feature_IG, cal_feature_IG_for_kg # input a molecule at a time batch_size = 1 dataset_filename = config["dataset"] if "dataset_test" in config: dataset_filename = config["dataset_test"] all_data, info = load_data(config, filename=dataset_filename, prohibit_shuffle=True) model = CoreModel(sess, config, info) load_model_py(model, config["model.py"], is_train=False, feed_embedded_layer=True, batch_size=batch_size) placeholders = model.placeholders restore_ckpt(sess, config['load_model']) # calculate integrated gradients if config['visualize_type'] == 'graph': cal_feature_IG(sess, all_data, placeholders, info, config, model.prediction, args.ig_modal_target, args.ig_label_target, logger=tf.logging, model=model.nn, args=args) else: cal_feature_IG_for_kg(sess, all_data, placeholders, info, config, model.prediction, logger=tf.logging, model=model.nn, args=args)
def visualize(sess, config, args): from tensorflow.python import debug as tf_debug from kgcn.visualization import cal_feature_IG, cal_feature_IG_for_kg # 入力は1分子づつ batch_size = 1 # 入力データから、全データの情報, 学習用データの情報, 検証用データの情報, および # グラフに関する情報を順に取得する all_data, info = load_data(config, filename=config["dataset"], prohibit_shuffle=True) model = importlib.import_module(config["model.py"]) try: # emmbedingレイヤを使っているモデルの可視化。IGはemmbedingレイヤの出力を対象にして計算される。 placeholders = model.build_placeholders(info, config, batch_size=batch_size, feed_embedded_layer=True) except: placeholders = model.build_placeholders(info, config, batch_size=batch_size) try: # emmbedingレイヤを使っているモデルの可視化。IGはemmbedingレイヤの出力を対象にして計算される。 _model, prediction, _, _, _ = model.build_model( placeholders, info, config, batch_size=batch_size, feed_embedded_layer=True) except: _model, prediction, _, _, _ = model.build_model(placeholders, info, config, batch_size=batch_size) #--- セッションの初期化 saver = tf.train.Saver() #tf.compat.v1.logging.info("[LOAD]", config["load_model"]) tf.logging.info("[LOAD]", config["load_model"]) saver.restore(sess, config["load_model"]) #--- integrated gradientsの計算 if config['visualize_type'] == 'graph': cal_feature_IG(sess, all_data, placeholders, info, prediction, args.ig_modal_target, args.ig_label_target, logger=tf.logging, model=_model) #logger=tf.compat.v1.logging, model=_model) else: cal_feature_IG_for_kg(sess, all_data, placeholders, info, config, prediction, logger=tf.logging, model=_model)