示例#1
0
def load_model(model_name, model_id, GPU='0'):
    from utils import label_map_util
    path_to_frozen_graph = r'/hdd6/Models/transmission_line/' \
                           r'export_model/{}/{}/frozen_inference_graph.pb'.format(model_name, model_id)
    path_to_labels = r'/home/lab/Documents/bohao/data/transmission_line/data/label_map_t.pbtxt'
    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = str(GPU)
    nn_utils.tf_warn_level(3)

    # load frozen tf model into memory
    detection_graph = tf.Graph()
    with detection_graph.as_default():
        od_graph_def = tf.GraphDef()
        with tf.gfile.GFile(path_to_frozen_graph, 'rb') as fid:
            serialized_graph = fid.read()
            od_graph_def.ParseFromString(serialized_graph)
            tf.import_graph_def(od_graph_def, name='')

    # load label map
    category_index = label_map_util.create_category_index_from_labelmap(
        path_to_labels, use_display_name=True)
    return detection_graph, category_index
示例#2
0
import tensorflow as tf
import uab_collectionFunctions
from nn import nn_utils
from bohaoCustom import uabMakeNetwork_UNet

if __name__ == '__main__':
    # settings
    nn_utils.tf_warn_level(3)
    model_dir = r'/hdd6/Models/UNET_rand_gird/UnetCrop_inria_aug_grid_0_PS(572, 572)_BS5_' \
                r'EP100_LR0.0001_DS60_DR0.1_SFN32'
    gpu = 0
    batch_size = 1
    input_size = [572, 572]
    #for city_name in ['Arlington', 'Atlanta', 'Austin', 'DC', 'NewHaven', 'NewYork', 'SanFrancisco', 'Seekonk']:
    for city_name in ['Norfolk']:
        tf.reset_default_graph()

        blCol = uab_collectionFunctions.uabCollection(city_name)
        blCol.readMetadata()
        file_list, parent_dir = blCol.getAllTileByDirAndExt([0, 1, 2])
        file_list_truth, parent_dir_truth = blCol.getAllTileByDirAndExt(3)
        img_mean = blCol.getChannelMeans([0, 1, 2])

        # make the model
        # define place holder
        X = tf.placeholder(tf.float32,
                           shape=[None, input_size[0], input_size[1], 3],
                           name='X')
        Z = tf.placeholder(tf.float32,
                           shape=[None, input_size[0], input_size[1], 3],
                           name='Z')