//  [python]
def from_snapshot(self, sess):
        # for v in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES) + tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES):
        #     print(v.name)

        if self.Restore_flag == -7:
            restore_dirs = '/'  # TODO set your pretrained model
            print('restore_from', restore_dirs)
            ckpt = tf.train.get_checkpoint_state(restore_dirs)
            sess.run(tf.global_variables_initializer())
            variables = [v for v in tf.global_variables() if not v.name.__contains__('Momentum')]

            for v in variables:
                print('snapshot:', v)
            saver = tf.train.Saver(variables)
            ckpt.model_checkpoint_path = self.switch_checkpoint_path(ckpt.model_checkpoint_path)
            saver.restore(sess, ckpt.model_checkpoint_path)
            print('Restoring model snapshots from {:s}'.format(ckpt.model_checkpoint_path))
        elif self.Restore_flag == -1:
            ckpt = tf.train.get_checkpoint_state(self.output_dir)
            saver = tf.train.Saver()
            saver.restore(sess, self.switch_checkpoint_path(ckpt.model_checkpoint_path))
            print('Restoring model snapshots from {:s}'.format(ckpt.model_checkpoint_path))

        if self.Restore_flag == 0:

            saver_t  = [var for var in tf.model_variables() if 'conv1' in var.name and 'conv1_sp' not in var.name]
            saver_t += [var for var in tf.model_variables() if 'conv2' in var.name and 'conv2_sp' not in var.name]
            saver_t += [var for var in tf.model_variables() if 'conv3' in var.name]
            saver_t += [var for var in tf.model_variables() if 'conv4' in var.name]
            saver_t += [var for var in tf.model_variables() if 'conv5' in var.name]
            saver_t += [var for var in tf.model_variables() if 'shortcut' in var.name]

            sess.run(tf.global_variables_initializer())
            # for var in tf.trainable_variables():
            #     print(var.name, var.eval().mean())

            print('Restoring model snapshots from {:s}'.format(self.pretrained_model))

            self.saver_restore = tf.train.Saver(saver_t)
            self.saver_restore.restore(sess, self.pretrained_model)

            # for var in tf.trainable_variables():
            #     print(var.name, var.eval().mean())


        if self.Restore_flag == 5 or self.Restore_flag == 6 or self.Restore_flag == 7:

            sess.run(tf.global_variables_initializer())
            # for var in tf.trainable_variables():
            #     print(var.name, var.eval().mean())
            if self.net.model_name.__contains__('res101'):
                model_backbone = 'resnet_v1_101'
            else:
                model_backbone = 'resnet_v1_50'
            
            print('Restoring model snapshots from {:s}'.format(self.pretrained_model), model_backbone)
            saver_t = {}
            
            # Add block0
            for ele in tf.model_variables():
                if model_backbone + '/conv1/weights' in ele.name or model_backbone + '/conv1/BatchNorm/beta' in ele.name or model_backbone + '/conv1/BatchNorm/gamma' in ele.name or model_backbone + '/conv1/BatchNorm/moving_mean' in ele.name or model_backbone + '/conv1/BatchNorm/moving_variance' in ele.name:
                    saver_t[ele.name[:-2]] = ele
            # Add block1
            for ele in tf.model_variables():
                if 'block1' in ele.name:
                    saver_t[ele.name[:-2]] = ele
           
            # Add block2
            for ele in tf.model_variables():
                if 'block2' in ele.name:
                    saver_t[ele.name[:-2]] = ele
                    
            # Add block3
            for ele in tf.model_variables():
                if 'block3' in ele.name:
                    saver_t[ele.name[:-2]] = ele
                
            # Add block4
            for ele in tf.model_variables():
                if 'block4' in ele.name:
                    saver_t[ele.name[:-2]] = ele
            
            self.saver_restore = tf.train.Saver(saver_t)
            self.saver_restore.restore(sess, self.pretrained_model)
            
            if self.Restore_flag >= 5:

                saver_t = {}
                # Add block5
                for ele in tf.model_variables():
                    if 'block4' in ele.name:
                        saver_t[ele.name[:-2]] = [var for var in tf.model_variables() if ele.name[:-2].replace('block4','block5') in var.name][0]
         
                
                self.saver_restore = tf.train.Saver(saver_t)
                self.saver_restore.restore(sess, self.pretrained_model)
            

            if self.Restore_flag >= 6:
                saver_t = {}
                # Add block6
                for ele in tf.model_variables():
                    if 'block4' in ele.name:
                        saver_t[ele.name[:-2]] = [var for var in tf.model_variables() if ele.name[:-2].replace('block4','block6') in var.name][0]
         
                
                self.saver_restore = tf.train.Saver(saver_t)
                self.saver_restore.restore(sess, self.pretrained_model)
                
            if self.Restore_flag >= 7:

                saver_t = {}
                # Add block7
                for ele in tf.model_variables():
                    if 'block4' in ele.name:
                        saver_t[ele.name[:-2]] = [var for var in tf.model_variables() if ele.name[:-2].replace('block4','block7') in var.name][0]
         
            
                self.saver_restore = tf.train.Saver(saver_t)
                self.saver_restore.restore(sess, self.pretrained_model)