# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import

import numpy as np

from alpharotate.utils.pretrain_zoo import PretrainModelZoo
from configs._base_.models.retinanet_r50_fpn import *
from configs._base_.datasets.dota_detection import *
from configs._base_.schedules.schedule_1x import *

# schedule
BATCH_SIZE = 1
GPU_GROUP = "0,1,2"
NUM_GPU = len(GPU_GROUP.strip().split(','))
LR = 1e-3
SAVE_WEIGHTS_INTE = 11725 * 2
DECAY_EPOCH = [8, 11, 20]
MAX_EPOCH = 12
WARM_EPOCH = 1 / 16.
DECAY_STEP = np.array(DECAY_EPOCH, np.int32) * SAVE_WEIGHTS_INTE
MAX_ITERATION = SAVE_WEIGHTS_INTE * MAX_EPOCH
WARM_SETP = int(WARM_EPOCH * SAVE_WEIGHTS_INTE)

# dataset
DATASET_NAME = 'DIOR-R'
CLASS_NUM = 20

# model
# backbone
pretrain_zoo = PretrainModelZoo()
PRETRAINED_CKPT = pretrain_zoo.pretrain_weight_path(NET_NAME, ROOT_PATH)
TRAINED_CKPT = os.path.join(ROOT_PATH, 'output/trained_weights')

# bbox head
NUM_SUBNET_CONV = 4
LEVEL = ['P3', 'P4', 'P5', 'P6', 'P7']
BASE_ANCHOR_SIZE_LIST = [32, 64, 128, 256, 512]
ANCHOR_STRIDE = [8, 16, 32, 64, 128]
ANCHOR_SCALES = [2 ** 0, 2 ** (1.0 / 3.0), 2 ** (2.0 / 3.0)]
ANCHOR_RATIOS = [1, 1 / 2, 2.]

# loss
CLS_WEIGHT = 1.0
REG_WEIGHT = 0.01

VERSION = 'RetinaNet_DIOR_R_KF_2x_20211025'

"""
RetinaNet-H + KF
FLOPs: 844274464;    Trainable params: 32553441
cls : dam|| Recall: 0.4795539033457249 || Precison: 0.028752925442995653|| AP: 0.23561300339814373
F1:0.34136049417722614 P:0.37117903930131 R:0.3159851301115242
cls : vehicle|| Recall: 0.2964339339339339 || Precison: 0.15901173912168012|| AP: 0.2636707550950283
F1:0.36622934325111256 P:0.7049636285836542 R:0.24737237237237236
cls : Expressway-toll-station|| Recall: 0.559593023255814 || Precison: 0.05075138412865805|| AP: 0.5337544176253854
F1:0.6405182813498403 P:0.8955613577023499 R:0.498546511627907
cls : golffield|| Recall: 0.8678260869565217 || Precison: 0.10983931322914374|| AP: 0.7444755688613637
F1:0.7865118834390905 P:0.8519269776876268 R:0.7304347826086957
cls : stadium|| Recall: 0.8497023809523809 || Precison: 0.12021052631578948|| AP: 0.6591428142859357
F1:0.6549658356787627 P:0.7466666666666667 R:0.5833333333333334
cls : baseballfield|| Recall: 0.7303436225975539 || Precison: 0.30924784217016027|| AP: 0.6739694039512543
F1:0.746624517101667 P:0.9363197189284146 R:0.6208503203261503
cls : harbor|| Recall: 0.533011272141707 || Precison: 0.027187751548305487|| AP: 0.2965631760079385
F1:0.39205915487775866 P:0.4508162411050649 R:0.3468599033816425
cls : trainstation|| Recall: 0.550098231827112 || Precison: 0.039486673247778874|| AP: 0.35869093731277907
F1:0.42983106290688566 P:0.6028368794326241 R:0.33398821218074654
cls : airport|| Recall: 0.512012012012012 || Precison: 0.03372231012658228|| AP: 0.27170327719970855
F1:0.39619152891661735 P:0.41946308724832215 R:0.37537537537537535
cls : groundtrackfield|| Recall: 0.9039787798408488 || Precison: 0.12025405786873677|| AP: 0.7705534868898014
F1:0.7881931035328766 P:0.7828362114076399 R:0.793633952254642
cls : storagetank|| Recall: 0.4917169641710543 || Precison: 0.4206613688797744|| AP: 0.4410642761006471
F1:0.5679154063641412 P:0.8230131643100926 R:0.43354308462822655
cls : windmill|| Recall: 0.6367578385590393 || Precison: 0.166|| AP: 0.5279236157702751
F1:0.6336624139802689 P:0.7706641184902054 R:0.538025350233489
cls : basketballcourt|| Recall: 0.8984156570363467 || Precison: 0.1660494358797692|| AP: 0.8100225277468716
F1:0.8879577496266513 P:0.9368856699430936 R:0.8438956197576887
cls : airplane|| Recall: 0.6847296639064783 || Precison: 0.4468727648414528|| AP: 0.6203098629997816
F1:0.7138680066967261 P:0.8777540867093105 R:0.6015586945932782
cls : tenniscourt|| Recall: 0.8699441645104181 || Precison: 0.3361751394590043|| AP: 0.8085657139245744
F1:0.8626011632309513 P:0.9419542083198968 R:0.7955876344818195
cls : chimney|| Recall: 0.7914645974781765 || Precison: 0.1267474370922647|| AP: 0.7261466647548951
F1:0.8252163376497641 P:0.9601029601029601 R:0.7235693501454898
cls : bridge|| Recall: 0.36655079181151023 || Precison: 0.053013798111837325|| AP: 0.24568533332958103
F1:0.3383241735186069 P:0.4940652818991098 R:0.2572421784472769
cls : ship|| Recall: 0.6972659580514977 || Precison: 0.41228070175438597|| AP: 0.5974751660207812
F1:0.6870605014135313 P:0.7921832083735432 R:0.6065764792815325
cls : Expressway-Service-area|| Recall: 0.8064516129032258 || Precison: 0.06181124611472167|| AP: 0.6803611325349901
F1:0.7318971815704155 P:0.7984749455337691 R:0.6755760368663595
cls : overpass|| Recall: 0.5662177328843996 || Precison: 0.05705077462399638|| AP: 0.4247928558962544
F1:0.5223013572664607 P:0.6722614840989399 R:0.4270482603815937
mAP is : 0.5345241994852994
"""
