124 lines
2.5 KiB
Python
124 lines
2.5 KiB
Python
import json
|
|
import shutil
|
|
import os
|
|
import numpy as np
|
|
source_path = '/srv/ftp/hummingbird/2021'
|
|
#target_path = '/home/thebears/Videos/ftp'
|
|
target_path = '/home/thebears/data/ftplinks'
|
|
import scipy.stats
|
|
target_mean = 0.4
|
|
target_std = 1
|
|
|
|
gauss = scipy.stats.norm(target_mean, target_std)
|
|
|
|
have_json = set()
|
|
for di, _, fns in os.walk(source_path):
|
|
for fn in fns:
|
|
if fn.endswith('.json'):
|
|
have_json.add(os.path.join(di, fn))
|
|
|
|
|
|
|
|
|
|
def box_area(box):
|
|
return (box[3]-box[1]) * (box[2] - box[0]) / 100000
|
|
|
|
|
|
do_stop = False
|
|
fracs = dict()
|
|
|
|
saveo = None
|
|
saveb = None
|
|
|
|
def gaussian(x, mu = target_mean, sig = target_std):
|
|
return np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))
|
|
|
|
scc = list()
|
|
for c_js in have_json:
|
|
hits = 0
|
|
total = 0
|
|
o = json.load(open(c_js,'r'))
|
|
if c_js.endswith('Hummingbird_01_20210701105440.json'):
|
|
saveo = o
|
|
|
|
if c_js.endswith('Hummingbird_01_20210627111405.json'):
|
|
saveb = o
|
|
|
|
avg = 0
|
|
max_sc = 0
|
|
|
|
for i in o:
|
|
# for x,b in zip(i['scores'], i['boxes']):
|
|
# scc.append((x,box_area(b)))
|
|
|
|
if len(i['scores']) > 0:
|
|
css = max(i['scores'])
|
|
mf = gaussian(box_area(i['boxes'][0]))
|
|
avg += css * mf / len(o)
|
|
|
|
|
|
fracs[c_js] = avg
|
|
|
|
|
|
|
|
|
|
ratios = dict()
|
|
for x,y in fracs.items():
|
|
ratios[x] = y
|
|
|
|
|
|
|
|
|
|
sorted_ratios = {x:ratios[x] for x in sorted(ratios, key=lambda x: ratios[x])}
|
|
|
|
|
|
import shutil
|
|
for d in os.listdir(target_path):
|
|
shutil.rmtree(target_path + '/' + d)
|
|
|
|
|
|
|
|
import math
|
|
dir_created = set()
|
|
for idx, (fname, ratio) in enumerate(sorted_ratios.items()):
|
|
cr = math.floor(100*ratio)
|
|
target_dir = os.path.join(target_path, '{0:02g}'.format(cr))
|
|
if not os.path.exists(target_dir) and target_dir not in dir_created:
|
|
os.mkdir(target_dir)
|
|
dir_created.add(target_dir)
|
|
else:
|
|
dir_created.add(target_dir)
|
|
|
|
|
|
|
|
source_file = fname.replace('.json','.mp4')
|
|
target_file = os.path.join(target_dir, os.path.basename(source_file))
|
|
|
|
|
|
os.symlink(source_file, target_file)
|
|
|
|
source_file = fname.replace('.json','.json')
|
|
target_file = os.path.join(target_dir, os.path.basename(source_file))
|
|
os.symlink(source_file, target_file)
|
|
# %%
|
|
|
|
if False:
|
|
plt.close('all')
|
|
inp = saveo
|
|
|
|
sco = list()
|
|
for x in inp:
|
|
if len(x['scores']) > 0:
|
|
cscore = max(x['scores'])
|
|
ar = box_area(x['boxes'][0])/ 100000
|
|
else:
|
|
cscore = 0
|
|
ar = 0
|
|
sco.append((cscore, ar))
|
|
|
|
plt.plot(sco)
|
|
|
|
# %%
|
|
distr = np.asarray(scc)
|
|
|