def load_scenes(): try: df = pd.read_pickle(data_dir(['scenes', 'origin', 'scenes.pkl'])) except: df = pd.read_csv(data_dir(['scenes', 'origin', 'scenes.csv'])) df['Polygon'] = df['Polygon'].apply(lambda s: eval(s)) df.to_pickle(data_dir(['scenes', 'origin', 'scenes.pkl'])) return df
def main(): df = load_scenes() df = df[df['Polygon'].map(is_interested)] filepath = lambda s: data_dir(['scenes', 'archives', '{}.csv'.format(s)]) df.to_csv(filepath('total'), index=None) df = df.sample(frac=1) # important, to shuffle the data for i in [1000, 1500, 2000, 2500, 5000, 10000, 15000, 20000, 50000, 75000, 100000]: if not os.path.isfile(filepath(str(i))): df.head(i).to_csv(filepath(str(i)), index=None) else: print(i, 'existed')
def visualize(vinfo, tag): roi = vinfo['roi'] selected = [] unselected = [] sorted_vinfo = sorted(vinfo['frames'].items(), key=lambda kv: float(kv[0])) frame_no = 0 frames = [] for timestamp, frame in sorted_vinfo: selected.append(frame['selected']) unselected = frame['unselected'] or [] frames.append(draw_frame(roi, selected, unselected)) frame_no += 1 print(frame_no, 'frame') writeGif(data_dir(['visualize', '{}.gif'.format(tag)]), frames, duration=0.7, dither=0)
def main(): MIN_PRODUCT_AREA = 0.011 small = [2, 4, 6, 8, 10, 12, 14, 16] median = [20, 40, 60, 80, 100] large = [] for ratio in small + median + large: path = data_dir(['rois', 'rect(x)_{}.csv'.format(ratio)]) size = ratio * MIN_PRODUCT_AREA if not os.path.isfile(path): rects = [[list(point) for point in rect] for rect in gen_axis_aligned_rectangle(1000, size)] # fig, ax = plt.subplots() # plot_polygons(ax, rects) # plt.show() df = pd.DataFrame([rects]).transpose() df.columns = ['Polygon'] df.to_csv(path, index=None) else: print(path, 'exists!')
import numpy as np import pandas as pd import json from utils.path import data_dir, fig_dir import matplotlib.pyplot as plt import matplotlib import os import re vinfo_path = data_dir(['visualize', 'bnb']) fig_path = fig_dir(['bnb_visual']) matplotlib.rcParams.update({'font.size': 18}) d = {} for dirpath, dirnames, filenames in os.walk(vinfo_path): for filename in filenames: btype, s = re.match("(\[.+\])(.+)", filename).groups() roi_ratio = s.strip().split('-')[2] if roi_ratio not in d: d[roi_ratio] = {} reports = json.load(open(os.path.join(dirpath, filename), 'r')) if len(reports) == 1: # old version reports = reports[0].items() else: # new version _ = {} for k in reports[0].keys(): _[k] = [report[k] for report in reports] reports = _.items() for k, v in reports:
def query_dir(l): return data_dir(['experiment', 'results', 'query'] + l)
def load_vinfo(n): discrete = json.load( open(data_dir(['visualize', 'vinfo', 'd{}_vinfo.json'.format(n)]))) continuous = json.load( open(data_dir(['visualize', 'vinfo', 'c{}_vinfo.json'.format(n)]))) return discrete, continuous
def main(): summary = json.load(open(data_dir(['experiment', 'results', 'summary.json']), 'r')) for sub_summary in summary: plot_summary(next(iter(sub_summary['variable'].keys())), sub_summary['reports'])
import json import numpy as np import pandas as pd import matplotlib.pyplot as plt from utils.path import data_dir deltas = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5] n_scenes = [] for i in [0.01, 0.02, 0.05, 0.1, 0.2, 0.5]: file_path = data_dir( ['experiment', 'results', 'query', '0.01-50-{}-15000.json'.format(i)]) reports = json.load(open(file_path, 'r')) n_scenes.append( np.mean([len(report['possible_scenes']) for report in reports])) df = pd.DataFrame([deltas, n_scenes]).transpose().sort_values(0) df.columns = ['roi_ratio', 'number_of_scenes'] df.plot(x='roi_ratio', y='number_of_scenes', marker='x') plt.savefig('n_scenes')