示例#1
0
def preprocess():
    WIDTH = 484
    HEIGHT = 240
    ENSEMBLE_N = 3

    # GET COLOR ENCODING AND ITS INDEX MAPPING
    colors = loadmat('../data/color150.mat')['colors']
    root = '..'
    names = {}
    with open('../data/object150_info.csv') as f:
        reader = csv.reader(f)
        next(reader)
        for row in reader:
            names[int(row[0])] = row[5].split(";")[0]
    idx_map = create_idx_group()
    colors, names = edit_colors_names_group(colors, names)

    # SETUP MODEL
    cfg_path = os.path.join('..', 'config',
                            'ade20k-mobilenetv2dilated-c1_deepsup.yaml')
    #cfg_path="config/ade20k-resnet18dilated-ppm_deepsup.yaml"
    model = setup_model(cfg_path, root, gpu=0)
    model.eval()

    # GET DATA AND PROCESS IMAGE
    data = np.load(os.path.join('..', 'test_set', 'cls1_rgb.npy'))
    data = data[:, :, ::-1]
    img = ImageLoad_cv2(data, WIDTH, HEIGHT, ENSEMBLE_N, True)

    # MODEL FEED
    predictions = predict(model, img, ENSEMBLE_N, gpu=0, is_silent=False)
    return predictions, colors, names, idx_map
示例#2
0
 def prepare_idx_map(self):
     self.idx_map = create_idx_group()
示例#3
0
if __name__ == '__main__':
    #Define the color dict
    import matplotlib.pyplot as plt
    WIDTH = 484
    HEIGHT = 240
    RESIZE_N = 2
    IS_SILENT = True
    colors = loadmat('data/color150.mat')['colors']
    root = ''
    names = {}
    with open('data/object150_info.csv') as f:
        reader = csv.reader(f)
        next(reader)
        for row in reader:
            names[int(row[0])] = row[5].split(";")[0]
    idx_map = create_idx_group()
    colors, names = edit_colors_names_group(colors, names)

    #take cls.npy as an example
    data = np.load(os.path.join('test_set', 'cls1_rgb.npy'))
    data = data[:, :, ::-1]
    cfg_path = os.path.join('config',
                            'ade20k-mobilenetv2dilated-c1_deepsup.yaml')
    #cfg_path="config/ade20k-resnet18dilated-ppm_deepsup.yaml"
    model = setup_model(cfg_path, root, gpu=0)
    model.eval()
    for i in range(5):
        torch.cuda.synchronize()
        start = time.time()
        img = ImageLoad_cv2(data, WIDTH, HEIGHT, RESIZE_N, is_silent=IS_SILENT)
        predictions = predict(model, img, RESIZE_N, gpu=0, is_silent=IS_SILENT)