コード例 #1
0
def main(cfg):
    os.environ['CUDA_VISIBLE_DEVICES'] = str(cfg.gpu_id)
    # ---------------------------------------------------------------
    # Set random seed
    print('=> pre-porcessing')
    seed = 123
    np.random.seed(seed)
    tf.set_random_seed(seed)
    # ---------------------------------------------------------------
    num_blocks = 3
    num_supports = 2
    placeholders = {
        'features': tf.placeholder(tf.float32, shape=(None, 3), name='features'),
        'img_inp': tf.placeholder(tf.float32, shape=(3, 224, 224, 3), name='img_inp'),
        'labels': tf.placeholder(tf.float32, shape=(None, 6), name='labels'),
        'support1': [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)],
        'support2': [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)],
        'support3': [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)],
        'faces': [tf.placeholder(tf.int32, shape=(None, 4)) for _ in range(num_blocks)],
        'edges': [tf.placeholder(tf.int32, shape=(None, 2)) for _ in range(num_blocks)],
        'lape_idx': [tf.placeholder(tf.int32, shape=(None, 10)) for _ in range(num_blocks)],  # for laplace term
        'pool_idx': [tf.placeholder(tf.int32, shape=(None, 2)) for _ in range(num_blocks - 1)],  # for unpooling
        'dropout': tf.placeholder_with_default(0., shape=()),
        'num_features_nonzero': tf.placeholder(tf.int32),
        'sample_coord': tf.placeholder(tf.float32, shape=(43, 3), name='sample_coord'),
        'cameras': tf.placeholder(tf.float32, shape=(3, 5), name='Cameras'),
        'faces_triangle': [tf.placeholder(tf.int32, shape=(None, 3)) for _ in range(num_blocks)],
        'sample_adj': [tf.placeholder(tf.float32, shape=(43, 43)) for _ in range(num_supports)],
    }

    root_dir = os.path.join(cfg.save_path, cfg.name)
    model_dir = os.path.join(cfg.save_path, cfg.name, 'models')
    log_dir = os.path.join(cfg.save_path, cfg.name, 'logs')
    plt_dir = os.path.join(cfg.save_path, cfg.name, 'plt')
    if not os.path.exists(root_dir):
        os.mkdir(root_dir)
        print('==> make root dir {}'.format(root_dir))
    if not os.path.exists(model_dir):
        os.mkdir(model_dir)
        print('==> make model dir {}'.format(model_dir))
    if not os.path.exists(log_dir):
        os.mkdir(log_dir)
        print('==> make log dir {}'.format(log_dir))
    if not os.path.exists(plt_dir):
        os.mkdir(plt_dir)
        print('==> make plt dir {}'.format(plt_dir))
    summaries_dir = os.path.join(cfg.save_path, cfg.name, 'summaries')
    train_loss = open('{}/train_loss_record.txt'.format(log_dir), 'a')
    train_loss.write('Net {} | Start training | lr =  {}\n'.format(cfg.name, cfg.lr))
    # -------------------------------------------------------------------
    print('=> build model')
    # Define model
    model = MeshNet(placeholders, logging=True, args=cfg)
    # ---------------------------------------------------------------
    print('=> load data')
    data = DataFetcher(file_list=cfg.train_file_path, data_root=cfg.train_data_path,
                       image_root=cfg.train_image_path, is_val=False, mesh_root=cfg.train_mesh_root)
    data.setDaemon(True)
    data.start()
    # ---------------------------------------------------------------
    print('=> initialize session')
    sesscfg = tf.ConfigProto()
    sesscfg.gpu_options.allow_growth = True
    sesscfg.allow_soft_placement = True
    sess = tf.Session(config=sesscfg)
    sess.run(tf.global_variables_initializer())
    train_writer = tf.summary.FileWriter(summaries_dir, sess.graph, filename_suffix='train')
    # ---------------------------------------------------------------
    if cfg.load_cnn:
        print('=> load pre-trained cnn')
        model.loadcnn(sess=sess, ckpt_path=cfg.pre_trained_cnn_path, step=cfg.cnn_step)
    if cfg.restore:
        print('=> load model')
        model.load(sess=sess, ckpt_path=model_dir, step=cfg.init_epoch)
    # ---------------------------------------------------------------
    # Load init ellipsoid and info about vertices and edges
    pkl = pickle.load(open('data/iccv_p2mpp.dat', 'rb'))
    # Construct Feed dict
    feed_dict = construct_feed_dict(pkl, placeholders)
    # ---------------------------------------------------------------
    train_number = data.number
    step = 0
    tflearn.is_training(True, sess)
    print('=> start train stage 2')

    for epoch in range(cfg.epochs):
        current_epoch = epoch + 1 + cfg.init_epoch
        epoch_plt_dir = os.path.join(plt_dir, str(current_epoch))
        if not os.path.exists(epoch_plt_dir):
            os.mkdir(epoch_plt_dir)
        mean_loss = 0
        all_loss = np.zeros(train_number, dtype='float32')
        for iters in range(train_number):
            step += 1
            # Fetch training data
            # need [img, label, pose(camera meta data), dataID]
            img_all_view, labels, poses, data_id, mesh = data.fetch()
            feed_dict.update({placeholders['features']: mesh})
            feed_dict.update({placeholders['img_inp']: img_all_view})
            feed_dict.update({placeholders['labels']: labels})
            feed_dict.update({placeholders['cameras']: poses})
            # ---------------------------------------------------------------
            _, dists, summaries, out1l, out2l = sess.run([model.opt_op, model.loss, model.merged_summary_op, model.output1l, model.output2l], feed_dict=feed_dict)
            # ---------------------------------------------------------------
            all_loss[iters] = dists
            mean_loss = np.mean(all_loss[np.where(all_loss)])
            print('Epoch {}, Iteration {}, Mean loss = {}, iter loss = {}, {}, data id {}'.format(current_epoch, iters + 1, mean_loss, dists, data.queue.qsize(), data_id))
            train_writer.add_summary(summaries, step)
            if (iters + 1) % 1000 == 0:
                plot_scatter(pt=out2l, data_name=data_id, plt_path=epoch_plt_dir)
        # ---------------------------------------------------------------
        # Save model
        model.save(sess=sess, ckpt_path=model_dir, step=current_epoch)
        train_loss.write('Epoch {}, loss {}\n'.format(current_epoch, mean_loss))
        train_loss.flush()
    # ---------------------------------------------------------------
    data.shutdown()
    print('CNN-GCN Optimization Finished!')
コード例 #2
0
def main(cfg):
    os.environ['CUDA_VISIBLE_DEVICES'] = str(0)
    # ---------------------------------------------------------------
    # Set random seed
    print('=> pre-porcessing')
    seed = 123
    np.random.seed(seed)
    tf.set_random_seed(seed)
    # ---------------------------------------------------------------
    num_blocks = 3
    num_supports = 2
    placeholders = {
        'features':
        tf.placeholder(tf.float32, shape=(None, 3), name='features'),
        'img_inp':
        tf.placeholder(tf.float32, shape=(3, 224, 224, 3), name='img_inp'),
        'labels':
        tf.placeholder(tf.float32, shape=(None, 6), name='labels'),
        'support1':
        [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)],
        'support2':
        [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)],
        'support3':
        [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)],
        'faces':
        [tf.placeholder(tf.int32, shape=(None, 4)) for _ in range(num_blocks)],
        'edges':
        [tf.placeholder(tf.int32, shape=(None, 2)) for _ in range(num_blocks)],
        'lape_idx': [
            tf.placeholder(tf.int32, shape=(None, 10))
            for _ in range(num_blocks)
        ],  # for laplace term
        'pool_idx': [
            tf.placeholder(tf.int32, shape=(None, 2))
            for _ in range(num_blocks - 1)
        ],  # for unpooling
        'dropout':
        tf.placeholder_with_default(0., shape=()),
        'num_features_nonzero':
        tf.placeholder(tf.int32),
        'sample_coord':
        tf.placeholder(tf.float32, shape=(43, 3), name='sample_coord'),
        'cameras':
        tf.placeholder(tf.float32, shape=(3, 5), name='Cameras'),
        'faces_triangle':
        [tf.placeholder(tf.int32, shape=(None, 3)) for _ in range(num_blocks)],
        'sample_adj': [
            tf.placeholder(tf.float32, shape=(43, 43))
            for _ in range(num_supports)
        ],
    }

    # step = cfg.test_epoch
    # root_dir = os.path.join(cfg.save_path, cfg.name)
    model1_dir = os.path.join('results', 'coarse_mvp2m', 'models')
    model2_dir = os.path.join('results', 'refine_p2mpp', 'models')
    # predict_dir = os.path.join(cfg.save_path, cfg.name, 'predict', str(step))
    # if not os.path.exists(predict_dir):
    #     os.makedirs(predict_dir)
    #     print('==> make predict_dir {}'.format(predict_dir))
    # -------------------------------------------------------------------
    print('=> build model')
    # Define model
    model1 = MVP2MNet(placeholders, logging=True, args=cfg)
    model2 = P2MPPNet(placeholders, logging=True, args=cfg)
    # ---------------------------------------------------------------
    print('=> load data')
    demo_img_list = [
        'data/demo/plane1.png', 'data/demo/plane2.png', 'data/demo/plane3.png'
    ]
    img_all_view = load_demo_image(demo_img_list)
    cameras = np.loadtxt('data/demo/cameras.txt')
    # data = DataFetcher(file_list=cfg.test_file_path, data_root=cfg.test_data_path, image_root=cfg.test_image_path, is_val=True)
    # data.setDaemon(True)
    # data.start()
    # ---------------------------------------------------------------
    print('=> initialize session')
    sesscfg = tf.ConfigProto()
    sesscfg.gpu_options.allow_growth = True
    sesscfg.allow_soft_placement = True
    sess = tf.Session(config=sesscfg)
    sess.run(tf.global_variables_initializer())
    # sess2 = tf.Session(config=sesscfg)
    # sess2.run(tf.global_variables_initializer())
    # ---------------------------------------------------------------
    model1.load(sess=sess, ckpt_path=model1_dir, step=50)
    model2.load(sess=sess, ckpt_path=model2_dir, step=10)
    # exit(0)
    # ---------------------------------------------------------------
    # Load init ellipsoid and info about vertices and edges
    pkl = pickle.load(open('data/iccv_p2mpp.dat', 'rb'))
    # Construct Feed dict
    feed_dict = construct_feed_dict(pkl, placeholders)
    # ---------------------------------------------------------------
    tflearn.is_training(False, sess)
    print('=> start test stage 1')
    feed_dict.update({placeholders['img_inp']: img_all_view})
    feed_dict.update({placeholders['labels']: np.zeros([10, 6])})
    feed_dict.update({placeholders['cameras']: cameras})
    stage1_out3 = sess.run(model1.output3, feed_dict=feed_dict)

    print('=> start test stage 2')
    feed_dict.update({placeholders['features']: stage1_out3})
    vert = sess.run(model2.output2l, feed_dict=feed_dict)
    vert = np.hstack((np.full([vert.shape[0], 1], 'v'), vert))
    face = np.loadtxt('data/face3.obj', dtype='|S32')
    mesh = np.vstack((vert, face))

    pred_path = 'data/demo/predict.obj'
    np.savetxt(pred_path, mesh, fmt='%s', delimiter=' ')

    print('=> save to {}'.format(pred_path))
コード例 #3
0
def main(cfg):
    physical_devices = tf.config.list_physical_devices('GPU')
    try:
        tf.config.experimental.set_memory_growth(physical_devices[0], True)
    except:
        # Invalid device or cannot modify virtual devices once initialized.
        pass
    os.environ['CUDA_VISIBLE_DEVICES'] = str(cfg.gpu_id)
    # pre-processing
    print('=> pre-processing:参数初始化ing')
    seed = 123
    np.random.seed(seed)
    # ---------------------------------------------------------------
    #num_blocks = 3
    #num_supports = 2
    #name: 'coarse_mvp2m'
    #save_path: 'results'
    root_dir = os.path.join(cfg.save_path, cfg.name)
    print(cfg.save_path)
    model_dir = os.path.join(cfg.save_path, cfg.name, 'models')
    log_dir = os.path.join(cfg.save_path, cfg.name, 'logs')
    plt_dir = os.path.join(cfg.save_path, cfg.name, 'plt')
    if not os.path.exists(root_dir):
        os.makedirs(root_dir)
        print('==> make root dir {}'.format(root_dir))
    if not os.path.exists(model_dir):
        os.makedirs(model_dir)
        print('==> make model dir {}'.format(model_dir))
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)
        print('==> make log dir {}'.format(log_dir))
    if not os.path.exists(plt_dir):
        os.makedirs(plt_dir)
        print('==> make plt dir {}'.format(plt_dir))
    train_loss = open('{}/train_loss_record.txt'.format(log_dir), 'a')
    train_loss.write('Net {} | Start training | lr =  {}\n'.format(
        cfg.name, cfg.lr))

    #data_loading
    print("=> data loading:数据加载ing")
    data = DataFetcher(file_list=cfg.train_file_path,
                       data_root=cfg.train_data_path,
                       image_root=cfg.train_image_path,
                       is_val=False)
    data.setDaemon(True)
    data.start()
    # ---------------------------------------------------------------
    # Load init ellipsoid and info about vertices and edges
    pkl = pickle.load(open('data/iccv_p2mpp.dat', 'rb'))
    # Construct Feed dict
    edges, faces, features, support1, support2, support3, pool_idx, lape_idx, faces_triangle, sample_adj, sample_coord = tools.construct_feed_dict(
        pkl)
    num_features_nonzero = None
    dropout = 0
    # ---------------------------------------------------------------
    #Define model
    print("=> model loading:模型加载ing")
    features = tf.convert_to_tensor(features, dtype=tf.float32)
    #-------------------------------
    #是否加载预训练模型  Default:False
    #-------------------------------
    pre_train = False
    if pre_train == True:
        model = tf.keras.models.load_model(
            '/workspace/3D/tf2_gcn-main/results/coarse_mvp2m/models/20200222model'
        )
    else:
        model = GCN.GCN_model(placeholders_features=features,
                              num_features_nonzero=num_features_nonzero,
                              placeholder_dropout=dropout,
                              pool_idx=pool_idx,
                              args=cfg,
                              support1=support1,
                              support2=support2,
                              support3=support3,
                              lape_idx=lape_idx,
                              edges=edges,
                              faces_triangle=faces_triangle)
    print('模型加载完成')
    #-------------------------------
    #是否加载预训练权重  Default:False
    #-------------------------------
    pre_weight = True
    if pre_weight == True:
        model.load_weights(
            '/workspace/3D/tf2_gcn-main/results/coarse_mvp2m/models/20200223model_weights/epoch1'
        )
    #权重保存位置
    model_weights_save_path = '/workspace/3D/tf2_gcn-main/results/coarse_mvp2m/models/20200223model_weights/epoch'

    print('=> start train ')

    def get_loss(output1, output2, output3, output1_2, output2_2, features,
                 trainable_variables, labels, edges, faces_triangle, lape_idx):
        '''损失函数'''
        # # Weight decay loss
        loss = tf.zeros([])
        # Cross entropy error
        # Pixel2mesh loss
        loss += mesh_loss(pred=output1,
                          labels=labels,
                          edges=edges,
                          faces_triangle=faces_triangle,
                          block_id=1)
        loss += mesh_loss(pred=output2,
                          labels=labels,
                          edges=edges,
                          faces_triangle=faces_triangle,
                          block_id=2)
        loss += mesh_loss(pred=output3,
                          labels=labels,
                          edges=edges,
                          faces_triangle=faces_triangle,
                          block_id=3)
        loss += laplace_loss(pred1=features,
                             pred2=output1,
                             lape_idx=lape_idx,
                             block_id=1)
        loss += laplace_loss(pred1=output1_2,
                             pred2=output2,
                             lape_idx=lape_idx,
                             block_id=2)
        loss += laplace_loss(pred1=output2_2,
                             pred2=output3,
                             lape_idx=lape_idx,
                             block_id=3)
        # Weight decay loss
        #conv_layers = list(range(1, 15)) + list(range(17, 31)) + list(range(33, 48))
        #for layer_id in conv_layers:
        for var1 in trainable_variables:
            for var in var1:
                loss += 5e-6 * tf.nn.l2_loss(var)
        return loss

    optimizer = tf.keras.optimizers.Adam(lr=cfg.lr)

    @tf.function(experimental_relax_shapes=True)
    def train_step(img_with_cameras, labels):
        with tf.GradientTape() as tape:
            output1, output2, output3, output1_2, output2_2, trainable_variables = model(
                img_with_cameras)
            loss = get_loss(output1, output2, output3, output1_2, output2_2,
                            features, trainable_variables, labels, edges,
                            faces_triangle, lape_idx)
        grads = tape.gradient(loss, model.trainable_variables)
        optimizer.apply_gradients(zip(grads, model.trainable_variables))
        return loss, output3

    train_number = data.number
    step = 0
    for epoch in range(cfg.epochs):
        # 在下一个epoch开始时,重置评估指标
        current_epoch = epoch + 1 + cfg.init_epoch
        epoch_plt_dir = os.path.join(plt_dir, str(current_epoch))
        if not os.path.exists(epoch_plt_dir):
            os.mkdir(epoch_plt_dir)
        mean_loss = 0
        all_loss = np.zeros(train_number, dtype='float32')
        #for iters in range(train_number):
        for iters in range(50):
            #train_number  35010
            step += 1
            img_all_view, labels, cameras, data_id, mesh = data.fetch()
            img_with_cameras = {}
            img_with_cameras.update({'img_all_view': img_all_view})
            img_with_cameras.update({'cameras': cameras})
            #cameras : [3,5]
            loss, output3 = train_step(img_with_cameras, labels)
            all_loss[iters] = loss
            mean_loss = np.mean(all_loss[np.where(all_loss)])
            if iters % 100 == 0:
                print(
                    'Epoch {}, Iteration {}, Mean loss = {}, iter loss = {}, {}, data id {}'
                    .format(current_epoch, iters + 1, mean_loss, loss,
                            data.queue.qsize(), data_id))
            if iters + 1 % 1000 == 0:
                train_loss.write(
                    'Epoch {}, Iteration {}, Mean loss = {}, iter loss = {}, {}, data id {}\n'
                    .format(current_epoch, iters + 1, mean_loss, loss,
                            data.queue.qsize(), data_id))
                plot_scatter(pt=output3,
                             data_name=data_id,
                             plt_path=epoch_plt_dir)
            train_loss.flush()
        model.save_weights(model_weights_save_path + str(current_epoch))
    print('模型保存完成,保存路径:', model_weights_save_path)
    # ---------------------------------------------------------------
    data.shutdown()
    #model save

    print('CNN-GCN Optimization Finished!')
コード例 #4
0
def main(cfg):
    os.environ['CUDA_VISIBLE_DEVICES'] = str(cfg.gpu_id)
    # ---------------------------------------------------------------
    # Set random seed
    print('=> pre-porcessing')
    seed = 123
    np.random.seed(seed)
    tf.set_random_seed(seed)
    # ---------------------------------------------------------------
    num_blocks = 3
    num_supports = 2
    placeholders = {
        'features': tf.placeholder(tf.float32, shape=(None, 3), name='features'),
        'img_inp': tf.placeholder(tf.float32, shape=(3, 224, 224, 3), name='img_inp'),
        'labels': tf.placeholder(tf.float32, shape=(None, 6), name='labels'),
        'support1': [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)],
        'support2': [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)],
        'support3': [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)],
        'faces': [tf.placeholder(tf.int32, shape=(None, 4)) for _ in range(num_blocks)],
        'edges': [tf.placeholder(tf.int32, shape=(None, 2)) for _ in range(num_blocks)],
        'lape_idx': [tf.placeholder(tf.int32, shape=(None, 10)) for _ in range(num_blocks)],  # for laplace term
        'pool_idx': [tf.placeholder(tf.int32, shape=(None, 2)) for _ in range(num_blocks - 1)],  # for unpooling
        'dropout': tf.placeholder_with_default(0., shape=()),
        'num_features_nonzero': tf.placeholder(tf.int32),
        'sample_coord': tf.placeholder(tf.float32, shape=(43, 3), name='sample_coord'),
        'cameras': tf.placeholder(tf.float32, shape=(3, 5), name='Cameras'),
        'faces_triangle': [tf.placeholder(tf.int32, shape=(None, 3)) for _ in range(num_blocks)],
        'sample_adj': [tf.placeholder(tf.float32, shape=(43, 43)) for _ in range(num_supports)],
    }

    step = cfg.test_epoch
    root_dir = os.path.join(cfg.save_path, cfg.name)
    model_dir = os.path.join(cfg.save_path, cfg.name, 'models')
    predict_dir = os.path.join(cfg.save_path, cfg.name, 'predict', str(step))
    if not os.path.exists(predict_dir):
        os.makedirs(predict_dir)
        print('==> make predict_dir {}'.format(predict_dir))
    # -------------------------------------------------------------------
    print('=> build model')
    # Define model
    model = MeshNetMVP2M(placeholders, logging=True, args=cfg)
    # ---------------------------------------------------------------
    print('=> load data')
    data = DataFetcher(file_list=cfg.test_file_path, data_root=cfg.test_data_path, image_root=cfg.test_image_path, is_val=True)
    data.setDaemon(True)
    data.start()
    # ---------------------------------------------------------------
    print('=> initialize session')
    sesscfg = tf.ConfigProto()
    sesscfg.gpu_options.allow_growth = True
    sesscfg.allow_soft_placement = True
    sess = tf.Session(config=sesscfg)
    sess.run(tf.global_variables_initializer())
    # ---------------------------------------------------------------
    model.load(sess=sess, ckpt_path=model_dir, step=step)
    # ---------------------------------------------------------------
    # Load init ellipsoid and info about vertices and edges
    pkl = pickle.load(open('data/iccv_p2mpp.dat', 'rb'))
    # Construct Feed dict
    feed_dict = construct_feed_dict(pkl, placeholders)
    # ---------------------------------------------------------------
    test_number = data.number
    tflearn.is_training(False, sess)
    print('=> start test stage 1')
    for iters in range(test_number):
        # Fetch training data
        # need [img, label, pose(camera meta data), dataID]
        img_all_view, labels, poses, data_id, mesh = data.fetch()
        feed_dict.update({placeholders['img_inp']: img_all_view})
        feed_dict.update({placeholders['labels']: labels})
        feed_dict.update({placeholders['cameras']: poses})
        # ---------------------------------------------------------------
        out1, out2, out3 = sess.run([model.output1, model.output2, model.output3], feed_dict=feed_dict)
        # ---------------------------------------------------------------
        # save GT
        label_path = os.path.join(predict_dir, data_id.replace('.dat', '_ground.xyz'))
        np.savetxt(label_path, labels)
        # save 1
        # out1_path = os.path.join(predict_dir, data_id.replace('.dat', '_predict_1.xyz'))
        # np.savetxt(out1_path, out1)
        # # save 2
        # out2_path = os.path.join(predict_dir, data_id.replace('.dat', '_predict_2.xyz'))
        # np.savetxt(out2_path, out2)
        # save 3
        out3_path = os.path.join(predict_dir, data_id.replace('.dat', '_predict.xyz'))
        np.savetxt(out3_path, out3)

        print('Iteration {}/{}, Data id {}'.format(iters + 1, test_number, data_id))

    # ---------------------------------------------------------------
    data.shutdown()
    print('CNN-GCN Optimization Finished!')
コード例 #5
0
def main(cfg):
    physical_devices = tf.config.list_physical_devices('GPU')
    try:
        tf.config.experimental.set_memory_growth(physical_devices[0], True)
    except:
        # Invalid device or cannot modify virtual devices once initialized.
        pass
    os.environ['CUDA_VISIBLE_DEVICES'] = str(cfg.gpu_id)
    # ---------------------------------------------------------------
    # Load init ellipsoid and info about vertices and edges

    # Construct Feed dict
    print('=> pre-processing:参数初始化ing')
    # ---------------------------------------------------------------
    #num_blocks = 3
    #num_supports = 2
    #name: 'coarse_mvp2m'
    #save_path: 'results'
    root_dir = os.path.join(cfg.save_path, cfg.name)
    print(cfg.save_path)
    model_dir = os.path.join(cfg.save_path, cfg.name, 'models')
    log_dir = os.path.join(cfg.save_path, cfg.name, 'logs')
    plt_dir = os.path.join(cfg.save_path, cfg.name, 'plt')
    if not os.path.exists(root_dir):
        os.makedirs(root_dir)
        print('==> make root dir {}'.format(root_dir))
    if not os.path.exists(model_dir):
        os.makedirs(model_dir)
        print('==> make model dir {}'.format(model_dir))
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)
        print('==> make log dir {}'.format(log_dir))
    if not os.path.exists(plt_dir):
        os.makedirs(plt_dir)
        print('==> make plt dir {}'.format(plt_dir))
    train_loss = open('{}/train_loss_record.txt'.format(log_dir), 'a')
    train_loss.write('Net {} | Start training | lr =  {}\n'.format(
        cfg.name, cfg.lr))

    #data_loading
    print("=> data loading:数据加载ing")
    # ---------------------------------------------------------------
    # Load init ellipsoid and info about vertices and edges
    pkl = pickle.load(open('data/iccv_p2mpp.dat', 'rb'))
    # Construct Feed dict
    edges, faces, features, support1, support2, support3, pool_idx, lape_idx, faces_triangle, sample_adj, sample_coord = tools.construct_feed_dict(
        pkl)
    num_features_nonzero = None
    dropout = 0
    # ---------------------------------------------------------------
    #Define model
    print("=> model loading:模型加载ing")
    #数据类型转换为Tensor类型!
    features = tf.convert_to_tensor(features, dtype=tf.float32)
    pre_train = False
    if pre_train == True:
        model = tf.keras.models.load_model(
            '/workspace/3D/tf2_gcn-main/results/coarse_mvp2m/models/20200222model'
        )
    else:
        model = GCN.GCN_model(placeholders_features=features,
                              num_features_nonzero=num_features_nonzero,
                              placeholder_dropout=dropout,
                              pool_idx=pool_idx,
                              args=cfg,
                              support1=support1,
                              support2=support2,
                              support3=support3,
                              lape_idx=lape_idx,
                              edges=edges,
                              faces_triangle=faces_triangle)
    model.load_weights(
        '/workspace/3D/tf2_gcn-main/results/coarse_mvp2m/models/20200223model_weights_epoch/1'
    )
    print('=> build model complete')
    print('=> start demo ')
    # -------------------------------------------------------------------
    # ---------------------------------------------------------------

    print('=> load data')
    demo_img_list = [
        'data/demo/plane1.png', 'data/demo/plane2.png', 'data/demo/plane3.png'
    ]

    img_all_view = tools.load_demo_image(demo_img_list)
    cameras = np.loadtxt('data/demo/cameras.txt')

    img_with_cameras = {}
    img_with_cameras.update({'img_all_view': img_all_view})
    img_with_cameras.update({'cameras': cameras})
    output1, output2, output3, output1_2, output2_2, trainable_variables = model(
        img_with_cameras)
    #loss = get_loss(output1,output2,output3,output1_2,output2_2,features,trainable_variables,labels,edges,faces_triangle,lape_idx)
    vert = output3
    vert = np.hstack((np.full([vert.shape[0], 1], 'v'), vert))
    face = np.loadtxt('data/face3.obj', dtype='|S32')
    mesh = np.vstack((vert, face))

    pred_path = 'data/demo/predict.obj'
    np.savetxt(pred_path, mesh, fmt='%s', delimiter=' ')

    print('=> save to {}'.format(pred_path))