yawc
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
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/ftp_links'
|
||||
|
||||
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):
|
||||
@@ -16,38 +20,69 @@ for di, _, fns in os.walk(source_path):
|
||||
|
||||
|
||||
|
||||
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:
|
||||
total += 1
|
||||
# if len([x for x in i['scores'] if x > 0.1]) > 0:
|
||||
if len(i['boxes']) > 0:
|
||||
hits += 1
|
||||
|
||||
fracs[c_js] = [hits, total]
|
||||
# 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)
|
||||
|
||||
|
||||
if do_stop:
|
||||
break
|
||||
fracs[c_js] = avg
|
||||
|
||||
|
||||
|
||||
|
||||
ratios = dict()
|
||||
for x,y in fracs.items():
|
||||
ratios[x] = y[0]/y[1]
|
||||
# %%
|
||||
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 fname, ratio in ratios.items():
|
||||
cr = math.floor(ratio * 10)/10
|
||||
target_dir = os.path.join(target_path, str(cr))
|
||||
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)
|
||||
@@ -58,5 +93,31 @@ for fname, ratio in ratios.items():
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user