# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 'Python 3.8.8 64-bit (''recycle'': conda)'
#     name: python3
# ---

from f1score import *

# +
# DIR_PATH = '/ssd_2/RecycleTrash/yolo/images/test_2020AGC_452'
# DIR_PATH = '/ssd_2/RecycleTrash/yolo/images/test_2021AGC_30'
# DIR_PATH = '/ssd_2/RecycleTrash/yolo/images/test_211026_405'
# DIR_PATH = '/ssd_2/RecycleTrash/yolo/images/test_211103_400'
DIR_PATH = '/home/agc2021/dataset/'

true_dict = get_true_annotation('../seareale/config/config.yaml', one_path=DIR_PATH)
pred_dict = get_pred_annotation(f'../seareale/answersheet_4_03_seareale.json')

_, f1, con_mat, tn = AGC2021_f1score(true_dict, pred_dict)
_, f1_zero, con_mat_zero, tn_zero  = AGC2021_f1score(true_dict, pred_dict, include_zero=True)

# PREFIX = 'x6_test_800_s-1'
# _, _ = show_confMat(con_mat, PREFIX)
# _ = plot_f1score(f1, PREFIX, tn)
# _, _ = show_confMat(con_mat_zero, PREFIX+'_zero')
# _ = plot_f1score(f1_zero, PREFIX+'_zero', tn_zero)

# +
# 3 ensemble(2l, 1x(neck-det))
0.9257 0.9125 # None

# 4 ensemble(2l, 2x)
0.9317 0.9188 # None

0.9207 0.9079 # 0

# 6 ensemble(s, m, 2l, 2x)
0.9109 0.8975 # None



# neck-det ensemble
0.9205 0.9054 # None
0.9177 0.9028 # 0
# 1
0.9102 0.8951 # sat
0.9115 0.8966 # 0,1
0.9177 0.9028 # 0,sat
0.9142 0.8990 # 2,sat
0.9121 0.8974 # 0,2,sat

# l6_neck-det
# 0,1
# sat
# 0,sat
# 2,sat
# 0,2,sat

# x6_neck-det
# 0,1
# sat
# 0,sat
# 2,sat
# 0,2,sat

# x6_all
# 0,1
# sat
# 0,sat
# 2,sat
# 0,2,sat

# l6_all
# 0,1
# sat
# 0,sat
# 2,sat
# 0,2,sat

# -

0.9101 0.8934 # x6_neck-det_last
0.9011 0.8882 # x6_all_e26
0.9202 0.9072 # l6_neck-det_last
0.8953 0.8827 # l6_all_last

# +
from f1score import *

DIR_PATH = '/ssd_2/RecycleTrash/yolo/images/test_2021AGC_30'
true_dict = get_true_annotation('../seareale/config/config.yaml', one_path=DIR_PATH)

# +
json_list = sorted(list(Path('../seareale/').glob('*.json')))

for json_path in json_list:
    pred_dict = get_pred_annotation(json_path)
    macrof1, _, _, _  = AGC2021_f1score(true_dict, pred_dict, include_zero=True, print_result=False)
    
    print(f"{str(json_path).split('/')[-1][:-5]:>30s} : {macrof1}")
# -



# +
import os
os.environ["CUDA_VISIBLE_DEVICES"]="3"
import sys
sys.path.append('../seareale')
import torch
from models.yolo import Model

from torchinfo import summary
# -

train_ckpt = torch.load('../seareale/weights/x6_neck-det_last.pt')
train_ckpt_model = train_ckpt['model']

nc = 7
model = Model(train_ckpt_model.yaml, ch=3, nc=nc)

summary(model, input_size=(4, 3, 1280, 1280))

StarcoderdataJupyterScriptsDedupFiltered