code: """
  Usage Instructions:
  
  """
  import csv
  import numpy as np
  # import pickle
  import random
  import tensorflow as tf
  
  import pandas as pd
  
  from maml import MAML
  from scene_sampling import SLICProcessor, TaskSampling
  
  from tensorflow.python.platform import flags
  
  from utils import tasksbatch_generator, sample_generator, meta_train_test, save_tasks, read_tasks, \
      savepts_fortask
  
  from Unsupervised_Pretraining.DAS_pretraining import DAS
  
  from sklearn.metrics._classification import accuracy_score
  
  import os
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
  
  FLAGS = flags.FLAGS
  
  """hyperparameter setting"""
  """for task sampling"""
  flags.DEFINE_float('M', 250, 'determine how distance influence the segmentation')
  flags.DEFINE_integer('K', 256, 'number of superpixels')
  flags.DEFINE_integer('loop', 5, 'number of SLIC iterations')
  #flags.DEFINE_string('seg_path', './src_data/CompositeBands2.tif', 'path to segmentation result of tasks by SLIC')
  flags.DEFINE_string('str_region', '', 'the region to be sampling tasks')
  flags.DEFINE_string('landslide_pts', './src_data/samples_fj_rand.xlsx', 'path to (non)landslide samples')
  
  """for meta-train"""
  flags.DEFINE_integer('mode', 3, '0:meta train part of FJ, test the other part of FJ; \
                                   1:meta train FJ, test FL; \
                                   2:meta train part of FJ and FL, test the other part FJ; \
                                   3:meta train FJ and part of FL, test the other part FL')
  flags.DEFINE_string('path', 'tasks', 'folder path of tasks file(excel)')
  flags.DEFINE_string('basemodel', 'DAS', 'MLP: no unsupervised pretraining; DAS: pretraining with DAS')
  flags.DEFINE_string('norm', 'batch_norm', 'batch_norm, layer_norm, or None')
  flags.DEFINE_string('log', './tmp/data', 'batch_norm, layer_norm, or None')
  flags.DEFINE_string('logdir', './checkpoint_dir', 'directory for summaries and checkpoints.')
  
  flags.DEFINE_integer('num_classes', 2, 'number of classes used in classification (e.g. 2-way classification， landslide and nonlandslide).')
  flags.DEFINE_integer('dim_input', 16, 'dim of input data')
  flags.DEFINE_integer('dim_output', 2, 'dim of output data')
  flags.DEFINE_integer('meta_batch_size', 16, 'number of tasks sampled per meta-update, not nums tasks')
  flags.DEFINE_integer('num_samples_each_task', 12, 'number of samples sampling from each task when training, inner_batch_size')
  flags.DEFINE_integer('test_update_batch_size', -1, 'number of examples used for gradient update during adapting (K=1,3,5 in experiment, K-shot); -1: M.')
  flags.DEFINE_integer('metatrain_iterations', 5001, 'number of metatraining iterations.')
  flags.DEFINE_integer('num_updates', 5, 'number of inner gradient updates during training.')
  flags.DEFINE_integer('pretrain_iterations', 0, 'number of pre-training iterations.')
  flags.DEFINE_integer('num_samples', 2637, 'total number of number of samples in FJ and FL.')
  
  
  flags.DEFINE_float('update_lr', 1e-1, 'learning rate in meta-learning task')
  flags.DEFINE_float('meta_lr', 1e-4, 'the base learning rate of meta learning process')
  
  # flags.DEFINE_bool('train', False, 'True to train, False to test.')
  flags.DEFINE_bool('stop_grad', False, 'if True, do not use second derivatives in meta-optimization (for speed)')
  flags.DEFINE_bool('resume', True, 'resume training if there is a model available')
  
  def train(model, saver, sess, exp_string, tasks, resume_itr):
      SUMMARY_INTERVAL = 100
      SAVE_INTERVAL = 1000
      PRINT_INTERVAL = 1000
      TEST_PRINT_INTERVAL = PRINT_INTERVAL * 5
  
      print('Done model initializing, starting training...')
      prelosses, postlosses = [], []
      if resume_itr != FLAGS.pretrain_iterations + FLAGS.metatrain_iterations - 1:
          if FLAGS.log:
              train_writer = tf.summary.FileWriter(FLAGS.logdir + '/' + exp_string, sess.graph)
          for itr in range(resume_itr, FLAGS.pretrain_iterations + FLAGS.metatrain_iterations):
              batch_x, batch_y, cnt_sample = tasksbatch_generator(tasks, FLAGS.meta_batch_size
                                                 , FLAGS.num_samples_each_task,
                                                 FLAGS.dim_input, FLAGS.dim_output)  # task_batch[i]: (x, y, features)
              # batch_y = _transform_labels_to_network_format(batch_y, FLAGS.num_classes)
              # inputa = batch_x[:, :int(FLAGS.num_samples_each_task/2), :]  # a used for training
              # labela = batch_y[:, :int(FLAGS.num_samples_each_task/2), :]
              # inputb = batch_x[:, int(FLAGS.num_samples_each_task/2):, :]  # b used for testing
              # labelb = batch_y[:, int(FLAGS.num_samples_each_task/2):, :]
  
              inputa = batch_x[:, :int(len(batch_x[0]) / 2), :]  # a used for training
              labela = batch_y[:, :int(len(batch_y[0]) / 2), :]
              inputb = batch_x[:, int(len(batch_x[0]) / 2):, :]  # b used for testing
              labelb = batch_y[:, int(len(batch_y[0]) / 2):, :]
  
              feed_dict = {model.inputa: inputa, model.inputb: inputb, model.labela: labela,
                           model.labelb: labelb,  model.cnt_sample: cnt_sample}
  
              if itr < FLAGS.pretrain_iterations:
                  input_tensors = [model.pretrain_op]  # for comparison
              else:
                  input_tensors = [model.metatrain_op]  # meta_train
  
              if (itr % SUMMARY_INTERVAL == 0 or itr % PRINT_INTERVAL == 0):
                  input_tensors.extend([model.summ_op, model.total_loss1, model.total_losses2[FLAGS.num_updates-1]])
  
              result = sess.run(input_tensors, feed_dict)
  
              if itr % SUMMARY_INTERVAL == 0:
                  prelosses.append(result[-2])
                  if FLAGS.log:
                      train_writer.add_summary(result[1], itr)  # add summ_op
                  postlosses.append(result[-1])
  
              if (itr != 0) and itr % PRINT_INTERVAL == 0:
                  if itr < FLAGS.pretrain_iterations:
                      print_str = 'Pretrain Iteration ' + str(itr)
                  else:
                      print_str = 'Iteration ' + str(itr - FLAGS.pretrain_iterations)
                  print_str += ': ' + str(np.mean(prelosses)) + ', ' + str(np.mean(postlosses))
                  print(print_str)
                  # print('meta_lr:'+str(sess.run(model.meta_lr)))
                  prelosses, postlosses = [], []
              #  save model
              if (itr != 0) and itr % SAVE_INTERVAL == 0:
                  saver.save(sess, FLAGS.logdir + '/' + exp_string + '/model' + str(itr))
  
              # TODO: Once the meta loss arrive at certain threshold, break the iteration
          saver.save(sess, FLAGS.logdir + '/' + exp_string + '/model' + str(itr))
  
  
  def test(model, saver, sess, exp_string, elig_tasks, num_updates=5):
      # few-shot learn LSM model of each task
      # print('start evaluation...\n' + 'meta_lr:' + str(model.meta_lr) + 'update_lr:' + str(num_updates))
      print(exp_string)
      total_Ytest = []
      total_Ypred = []
      total_Ytest1 = []
      total_Ypred1 = []
      sum_accuracies = []
      sum_accuracies1 = []
      for i in range(len(elig_tasks)):
          batch_x, batch_y = sample_generator(elig_tasks[i], FLAGS.dim_input, FLAGS.dim_output)   # only one task samples
          if FLAGS.test_update_batch_size == -1:
              inputa = batch_x[:, :int(len(batch_x[0]) / 2), :]  # a used for fine tuning
              labela = batch_y[:, :int(len(batch_y[0]) / 2), :]
              inputb = batch_x[:, int(len(batch_x[0]) / 2):, :]  # b used for testing
              labelb = batch_y[:, int(len(batch_y[0]) / 2):, :]
          else:
              inputa = batch_x[:, :FLAGS.test_update_batch_size, :]  # setting K-shot K here
              labela = batch_y[:, :FLAGS.test_update_batch_size, :]
              inputb = batch_x[:, FLAGS.test_update_batch_size:, :]
              labelb = batch_y[:, FLAGS.test_update_batch_size:, :]
  
          #feed_dict = {model.inputa: inputa, model.inputb: inputb, model.labela: labela, model.labelb: labelb}
          """few-steps tuning"""
          with tf.variable_scope('model', reuse=True):  # np.normalize()里Variable重用
              task_output = model.forward(inputa[0], model.weights, reuse=True)
              task_loss = model.loss_func(task_output, labela[0])
              grads = tf.gradients(task_loss,list(model.weights.values()))
              gradients = dict(zip(model.weights.keys(), grads))
              fast_weights = dict(zip(model.weights.keys(), [model.weights[key] -
                             model.update_lr*gradients[key] for key in model.weights.keys()]))
              for j in range(num_updates - 1):
                  loss = model.loss_func(model.forward(inputa[0], fast_weights, reuse=True), labela[0])  # fast_weight和grads（stopped）有关系，但不影响这里的梯度计算
                  grads = tf.gradients(loss, list(fast_weights.values()))
                  gradients = dict(zip(fast_weights.keys(), grads))
                  fast_weights = dict(zip(fast_weights.keys(), [fast_weights[key] - model.update_lr*gradients[key] for key in fast_weights.keys()]))
              """后续考虑用跑op"""
              # for j in range(num_update):
              #     sess.run(model.pretrain_op, feed_dict=feed_dict)  # num_update次迭代 # 存储各task模型
              # saver.save(sess, './checkpoint_dir/task' + str(i) + 'model')
  
              """Test Evaluation"""
              output = model.forward(inputb[0], fast_weights, reuse=True)  # 注意测试model.weight是否为更新后值
              Y_array = sess.run(tf.nn.softmax(output))  # , feed_dict=feed_dict
              total_Ypred1.extend(Y_array)
              total_Ytest1.extend(labelb[0])  # save
  
              Y_test = []
              for j in range(len(labelb[0])):
                  Y_test.append(labelb[0][j][0])
                  total_Ytest.append(labelb[0][j][0])
              Y_pred = []
              for j in range(len(labelb[0])):
                  if Y_array[j][0] > Y_array[j][1]:
                      Y_pred.append(1)
                      total_Ypred.append(1)
                  else:
                      Y_pred.append(0)
                      total_Ypred.append(0)
              accuracy = accuracy_score(Y_test, Y_pred)
              sum_accuracies.append(accuracy)
              # print('Test_Accuracy: %f' % accuracy)
  
      # save prediction
      total_Ypred1 = np.array(total_Ypred1)
      total_Ytest1 = np.array(total_Ytest1)
      arr = np.hstack((total_Ypred1, total_Ytest1))
      writer = pd.ExcelWriter('mode' + str(FLAGS.mode) + 'predict.xlsx')
      data_df = pd.DataFrame(arr)
      data_df.to_excel(writer)
      writer.save()
      # measure performance
      total_Ypred = np.array(total_Ypred).reshape(len(total_Ypred),)
      total_Ytest = np.array(total_Ytest)
      total_accr = accuracy_score(total_Ytest, total_Ypred)
      print('Total_Accuracy: %f' % total_accr)
  
      """TP,TP,FN,FP"""
      TP = ((total_Ypred==1)*(total_Ytest==1)).astype(int).sum()
      FP = ((total_Ypred==1)*(total_Ytest==0)).astype(int).sum()
      FN = ((total_Ypred==0)*(total_Ytest==1)).astype(int).sum()
      TN = ((total_Ypred==0)*(total_Ytest==0)).astype(int).sum()
  
      Precision = TP / (TP+FP)
      Recall = TP / (TP+FN)
      F_measures = 2 * Precision * Recall / (Precision+Recall)
  
      print('Precision: %f' % Precision)
      print('Recall: %f' % Recall)
      print('F_measures: %f' % F_measures)
  
      # print('Mean_Accuracy: %f' % np.mean(np.array(sum_accuracies), axis=0))
      # # print('Mean_Accuracy_pre: %f' % np.mean(np.array(sum_accuracies1), axis=0))
      sess.close()
  
  
  def main():
      """unsupervised pretraining"""
      if not os.path.exists('./DAS_logs/savedmodel.npz'):
          print("start unsupervised pretraining")
          tmp = np.loadtxt('src_data/FJ_FL.csv', dtype=np.str, delimiter=",",encoding='UTF-8')
          tmp_feature = tmp[1:,:]
          np.random.shuffle(tmp_feature)  # shuffle
          DAS(tmp_feature)
  
      """任务采样"""
      taskspath_FJ = './seg_output/FJ_tasks.xlsx'
      taskspath_FL = './seg_output/FL_tasks.xlsx'
      fj_tasks, fl_tasks = [], []
      if os.path.exists(taskspath_FJ):
          # read tasks csv
          fj_tasks = read_tasks(taskspath_FJ)
          print('Done reading FJ tasks from previous SLIC result')
      else:
          print('start FJ tasks sampling...')
          FLAGS.str_region = 'FJ'
          FLAGS.landslide_pts = './src_data/samples_fj_rand.xlsx'
          p = SLICProcessor('./src_data/'+FLAGS.str_region+'/composite.tif', FLAGS.K, FLAGS.M)
          p.iterate_times(loop=FLAGS.loop)
          t = TaskSampling(p.clusters)
          fj_tasks = t.sampling(p.im_geotrans)  # tasks[i]:第i个task，(x, y, features)
          save_tasks(fj_tasks)
  
          savepts_fortask(p.clusters, './seg_output/' + FLAGS.str_region + 'pts_tasks.xlsx')
          print('Done saving FJ tasks to file!')
      if os.path.exists(taskspath_FL):
          # read tasks csv
          fl_tasks = read_tasks(taskspath_FL)
          print('Done reading FL tasks from previous SLIC result')
      else:
          print('start FL tasks sampling...')
          FLAGS.str_region = 'FL'
          FLAGS.landslide_pts = './src_data/samples_fl_rand.xlsx'
          p = SLICProcessor('./src_data/'+FLAGS.str_region+'/composite.tif', 96, FLAGS.M)
          p.iterate_times(loop=FLAGS.loop)
          t = TaskSampling(p.clusters)
          fl_tasks = t.sampling(p.im_geotrans)  # tasks[i]:第i个task，(x, y, features)
          save_tasks(fl_tasks)
  
          savepts_fortask(p.clusters, './seg_output/' + FLAGS.str_region + 'pts_tasks.xlsx')
          print('Done saving FL tasks to file!')
  
      # if FLAGS.train:
      #     test_num_updates = 5
      # else:
      #     test_num_updates = 10
      # if FLAGS.train == False:
      #     # always use meta batch size of 1 when testing.
      #     FLAGS.meta_batch_size = 1
  
      """meta_training"""
      model = MAML(FLAGS.dim_input, FLAGS.dim_output, test_num_updates=5)
      input_tensors = None
      model.construct_model(input_tensors=input_tensors, prefix='metatrain_')
      model.summ_op = tf.summary.merge_all()
  
      saver = loader = tf.train.Saver(tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES), max_to_keep=10)
  
      sess = tf.InteractiveSession()
  
      # init1 = tf.global_variables(scope='model')
      init = tf.global_variables()  # optimizer里会有额外variable需要初始化
      # print(sess.run(tf.report_uninitialized_variables()))
      sess.run(tf.variables_initializer(var_list=init))
  
      exp_string = 'mode'+str(FLAGS.mode)+'.mbs'+str(FLAGS.meta_batch_size)+'.ubs_'+\
          str(FLAGS.num_samples_each_task)+'.numstep' + str(FLAGS.num_updates) + \
                   '.updatelr' + str(FLAGS.update_lr) + '.meta_lr' + str(FLAGS.meta_lr)
  
      resume_itr = 0
      model_file = None
      tf.global_variables_initializer().run()  # 初始化全局变量
      tf.train.start_queue_runners()  # ？
      # 续点训练
      if FLAGS.resume or not FLAGS.train:
          model_file = tf.train.latest_checkpoint(FLAGS.logdir + '/' + exp_string)
          if model_file:
              ind1 = model_file.index('model')
              resume_itr = int(model_file[ind1 + 5:])
              print("Restoring model weights from " + model_file)
              saver.restore(sess, model_file)  # 以model_file初始化sess中图
  
      tasks_train, tasks_test = meta_train_test(fj_tasks, fl_tasks, mode=FLAGS.mode)
  
      train(model, saver, sess, exp_string, tasks_train, resume_itr)
  
      test(model, saver, sess, exp_string, tasks_test, num_updates=FLAGS.num_updates)
  
  
  if __name__ == "__main__":
      main()
  
apis: tensorflow.global_variables tensorflow.variables_initializer pandas.DataFrame tensorflow.python.platform.flags.DEFINE_integer numpy.mean sklearn.metrics._classification.accuracy_score tensorflow.python.platform.flags.DEFINE_string numpy.hstack tensorflow.get_collection tensorflow.python.platform.flags.DEFINE_float tensorflow.InteractiveSession tensorflow.global_variables_initializer tensorflow.summary.merge_all numpy.array tensorflow.nn.softmax tensorflow.train.latest_checkpoint tensorflow.summary.FileWriter tensorflow.train.start_queue_runners tensorflow.python.platform.flags.DEFINE_bool numpy.random.shuffle tensorflow.variable_scope numpy.loadtxt
api_extract: [(32, 'tensorflow.python.platform.flags.DEFINE_float', 'flags.DEFINE_float', (['"""M"""', '(250)', '"""determine how distance influence the segmentation"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (33, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""K"""', '(256)', '"""number of superpixels"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (34, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""loop"""', '(5)', '"""number of SLIC iterations"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (36, 'tensorflow.python.platform.flags.DEFINE_string', 'flags.DEFINE_string', (['"""str_region"""', '""""""', '"""the region to be sampling tasks"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (37, 'tensorflow.python.platform.flags.DEFINE_string', 'flags.DEFINE_string', (['"""landslide_pts"""', '"""./src_data/samples_fj_rand.xlsx"""', '"""path to (non)landslide samples"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (40, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""mode"""', '(3)', '"""0:meta train part of FJ, test the other part of FJ;                                  1:meta train FJ, test FL;                                  2:meta train part of FJ and FL, test the other part FJ;                                  3:meta train FJ and part of FL, test the other part FL"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (44, 'tensorflow.python.platform.flags.DEFINE_string', 'flags.DEFINE_string', (['"""path"""', '"""tasks"""', '"""folder path of tasks file(excel)"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (45, 'tensorflow.python.platform.flags.DEFINE_string', 'flags.DEFINE_string', (['"""basemodel"""', '"""DAS"""', '"""MLP: no unsupervised pretraining; DAS: pretraining with DAS"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (46, 'tensorflow.python.platform.flags.DEFINE_string', 'flags.DEFINE_string', (['"""norm"""', '"""batch_norm"""', '"""batch_norm, layer_norm, or None"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (47, 'tensorflow.python.platform.flags.DEFINE_string', 'flags.DEFINE_string', (['"""log"""', '"""./tmp/data"""', '"""batch_norm, layer_norm, or None"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (48, 'tensorflow.python.platform.flags.DEFINE_string', 'flags.DEFINE_string', (['"""logdir"""', '"""./checkpoint_dir"""', '"""directory for summaries and checkpoints."""'], {}), False, 'from tensorflow.python.platform import flags\n'), (50, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""num_classes"""', '(2)', '"""number of classes used in classification (e.g. 2-way classification， landslide and nonlandslide)."""'], {}), False, 'from tensorflow.python.platform import flags\n'), (51, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""dim_input"""', '(16)', '"""dim of input data"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (52, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""dim_output"""', '(2)', '"""dim of output data"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (53, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""meta_batch_size"""', '(16)', '"""number of tasks sampled per meta-update, not nums tasks"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (54, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""num_samples_each_task"""', '(12)', '"""number of samples sampling from each task when training, inner_batch_size"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (55, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""test_update_batch_size"""', '(-1)', '"""number of examples used for gradient update during adapting (K=1,3,5 in experiment, K-shot); -1: M."""'], {}), False, 'from tensorflow.python.platform import flags\n'), (56, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""metatrain_iterations"""', '(5001)', '"""number of metatraining iterations."""'], {}), False, 'from tensorflow.python.platform import flags\n'), (57, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""num_updates"""', '(5)', '"""number of inner gradient updates during training."""'], {}), False, 'from tensorflow.python.platform import flags\n'), (58, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""pretrain_iterations"""', '(0)', '"""number of pre-training iterations."""'], {}), False, 'from tensorflow.python.platform import flags\n'), (59, 'tensorflow.python.platform.flags.DEFINE_integer', 'flags.DEFINE_integer', (['"""num_samples"""', '(2637)', '"""total number of number of samples in FJ and FL."""'], {}), False, 'from tensorflow.python.platform import flags\n'), (62, 'tensorflow.python.platform.flags.DEFINE_float', 'flags.DEFINE_float', (['"""update_lr"""', '(0.1)', '"""learning rate in meta-learning task"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (63, 'tensorflow.python.platform.flags.DEFINE_float', 'flags.DEFINE_float', (['"""meta_lr"""', '(0.0001)', '"""the base learning rate of meta learning process"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (66, 'tensorflow.python.platform.flags.DEFINE_bool', 'flags.DEFINE_bool', (['"""stop_grad"""', '(False)', '"""if True, do not use second derivatives in meta-optimization (for speed)"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (67, 'tensorflow.python.platform.flags.DEFINE_bool', 'flags.DEFINE_bool', (['"""resume"""', '(True)', '"""resume training if there is a model available"""'], {}), False, 'from tensorflow.python.platform import flags\n'), (196, 'numpy.array', 'np.array', (['total_Ypred1'], {}), True, 'import numpy as np\n'), (197, 'numpy.array', 'np.array', (['total_Ytest1'], {}), True, 'import numpy as np\n'), (198, 'numpy.hstack', 'np.hstack', (['(total_Ypred1, total_Ytest1)'], {}), True, 'import numpy as np\n'), (200, 'pandas.DataFrame', 'pd.DataFrame', (['arr'], {}), True, 'import pandas as pd\n'), (205, 'numpy.array', 'np.array', (['total_Ytest'], {}), True, 'import numpy as np\n'), (206, 'sklearn.metrics._classification.accuracy_score', 'accuracy_score', (['total_Ytest', 'total_Ypred'], {}), False, 'from sklearn.metrics._classification import accuracy_score\n'), (241, 'os.path.exists', 'os.path.exists', (['taskspath_FJ'], {}), False, 'import os\n'), (257, 'os.path.exists', 'os.path.exists', (['taskspath_FL'], {}), False, 'import os\n'), (283, 'maml.MAML', 'MAML', (['FLAGS.dim_input', 'FLAGS.dim_output'], {'test_num_updates': '(5)'}), False, 'from maml import MAML\n'), (286, 'tensorflow.summary.merge_all', 'tf.summary.merge_all', ([], {}), True, 'import tensorflow as tf\n'), (290, 'tensorflow.InteractiveSession', 'tf.InteractiveSession', ([], {}), True, 'import tensorflow as tf\n'), (293, 'tensorflow.global_variables', 'tf.global_variables', ([], {}), True, 'import tensorflow as tf\n'), (304, 'tensorflow.train.start_queue_runners', 'tf.train.start_queue_runners', ([], {}), True, 'import tensorflow as tf\n'), (314, 'utils.meta_train_test', 'meta_train_test', (['fj_tasks', 'fl_tasks'], {'mode': 'FLAGS.mode'}), False, 'from utils import tasksbatch_generator, sample_generator, meta_train_test, save_tasks, read_tasks, savepts_fortask\n'), (142, 'utils.sample_generator', 'sample_generator', (['elig_tasks[i]', 'FLAGS.dim_input', 'FLAGS.dim_output'], {}), False, 'from utils import tasksbatch_generator, sample_generator, meta_train_test, save_tasks, read_tasks, savepts_fortask\n'), (230, 'os.path.exists', 'os.path.exists', (['"""./DAS_logs/savedmodel.npz"""'], {}), False, 'import os\n'), (232, 'numpy.loadtxt', 'np.loadtxt', (['"""src_data/FJ_FL.csv"""'], {'dtype': 'np.str', 'delimiter': '""","""', 'encoding': '"""UTF-8"""'}), True, 'import numpy as np\n'), (234, 'numpy.random.shuffle', 'np.random.shuffle', (['tmp_feature'], {}), True, 'import numpy as np\n'), (235, 'Unsupervised_Pretraining.DAS_pretraining.DAS', 'DAS', (['tmp_feature'], {}), False, 'from Unsupervised_Pretraining.DAS_pretraining import DAS\n'), (243, 'utils.read_tasks', 'read_tasks', (['taskspath_FJ'], {}), False, 'from utils import tasksbatch_generator, sample_generator, meta_train_test, save_tasks, read_tasks, savepts_fortask\n'), (249, 'scene_sampling.SLICProcessor', 'SLICProcessor', (["('./src_data/' + FLAGS.str_region + '/composite.tif')", 'FLAGS.K', 'FLAGS.M'], {}), False, 'from scene_sampling import SLICProcessor, TaskSampling\n'), (251, 'scene_sampling.TaskSampling', 'TaskSampling', (['p.clusters'], {}), False, 'from scene_sampling import SLICProcessor, TaskSampling\n'), (253, 'utils.save_tasks', 'save_tasks', (['fj_tasks'], {}), False, 'from utils import tasksbatch_generator, sample_generator, meta_train_test, save_tasks, read_tasks, savepts_fortask\n'), (255, 'utils.savepts_fortask', 'savepts_fortask', (['p.clusters', "('./seg_output/' + FLAGS.str_region + 'pts_tasks.xlsx')"], {}), False, 'from utils import tasksbatch_generator, sample_generator, meta_train_test, save_tasks, read_tasks, savepts_fortask\n'), (259, 'utils.read_tasks', 'read_tasks', (['taskspath_FL'], {}), False, 'from utils import tasksbatch_generator, sample_generator, meta_train_test, save_tasks, read_tasks, savepts_fortask\n'), (265, 'scene_sampling.SLICProcessor', 'SLICProcessor', (["('./src_data/' + FLAGS.str_region + '/composite.tif')", '(96)', 'FLAGS.M'], {}), False, 'from scene_sampling import SLICProcessor, TaskSampling\n'), (267, 'scene_sampling.TaskSampling', 'TaskSampling', (['p.clusters'], {}), False, 'from scene_sampling import SLICProcessor, TaskSampling\n'), (269, 'utils.save_tasks', 'save_tasks', (['fl_tasks'], {}), False, 'from utils import tasksbatch_generator, sample_generator, meta_train_test, save_tasks, read_tasks, savepts_fortask\n'), (271, 'utils.savepts_fortask', 'savepts_fortask', (['p.clusters', "('./seg_output/' + FLAGS.str_region + 'pts_tasks.xlsx')"], {}), False, 'from utils import tasksbatch_generator, sample_generator, meta_train_test, save_tasks, read_tasks, savepts_fortask\n'), (288, 'tensorflow.get_collection', 'tf.get_collection', (['tf.GraphKeys.TRAINABLE_VARIABLES'], {}), True, 'import tensorflow as tf\n'), (295, 'tensorflow.variables_initializer', 'tf.variables_initializer', ([], {'var_list': 'init'}), True, 'import tensorflow as tf\n'), (307, 'tensorflow.train.latest_checkpoint', 'tf.train.latest_checkpoint', (["(FLAGS.logdir + '/' + exp_string)"], {}), True, 'import tensorflow as tf\n'), (79, 'tensorflow.summary.FileWriter', 'tf.summary.FileWriter', (["(FLAGS.logdir + '/' + exp_string)", 'sess.graph'], {}), True, 'import tensorflow as tf\n'), (81, 'utils.tasksbatch_generator', 'tasksbatch_generator', (['tasks', 'FLAGS.meta_batch_size', 'FLAGS.num_samples_each_task', 'FLAGS.dim_input', 'FLAGS.dim_output'], {}), False, 'from utils import tasksbatch_generator, sample_generator, meta_train_test, save_tasks, read_tasks, savepts_fortask\n'), (156, 'tensorflow.variable_scope', 'tf.variable_scope', (['"""model"""'], {'reuse': '(True)'}), True, 'import tensorflow as tf\n'), (191, 'sklearn.metrics._classification.accuracy_score', 'accuracy_score', (['Y_test', 'Y_pred'], {}), False, 'from sklearn.metrics._classification import accuracy_score\n'), (204, 'numpy.array', 'np.array', (['total_Ypred'], {}), True, 'import numpy as np\n'), (303, 'tensorflow.global_variables_initializer', 'tf.global_variables_initializer', ([], {}), True, 'import tensorflow as tf\n'), (175, 'tensorflow.nn.softmax', 'tf.nn.softmax', (['output'], {}), True, 'import tensorflow as tf\n'), (119, 'numpy.mean', 'np.mean', (['postlosses'], {}), True, 'import numpy as np\n'), (119, 'numpy.mean', 'np.mean', (['prelosses'], {}), True, 'import numpy as np\n')]