# -*- 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(','))
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 = 1.0 / 5.0
REG_LOSS_MODE = 1  # IoU-Smooth L1

VERSION = 'RetinaNet_DIOR_R_2x_20211104'

"""
RetinaNet-H + 90 + IoU-Smooth L1
FLOPs: 844273774;    Trainable params: 32553441
cls : airplane|| Recall: 0.6147101802240623 || Precison: 0.32292732855680656|| AP: 0.5716916120966895
F1:0.6511231988751089 P:0.8466185928668876 R:0.5289819775937652
cls : airport|| Recall: 0.5195195195195195 || Precison: 0.0371483787846253|| AP: 0.2486333771744385
F1:0.3812551258213531 P:0.4125874125874126 R:0.35435435435435436
cls : baseballfield|| Recall: 0.7288875946418171 || Precison: 0.3126795752654591|| AP: 0.6762147836319792
F1:0.7413928967491362 P:0.9482758620689655 R:0.6086196854979615
cls : basketballcourt|| Recall: 0.8863000931966449 || Precison: 0.12998906506287589|| AP: 0.8051198110015625
F1:0.8617313533993015 P:0.9182920400632578 R:0.8117427772600186
cls : bridge|| Recall: 0.32367709540363077 || Precison: 0.03769850195690314|| AP: 0.21361320408181927
F1:0.2960481128384506 P:0.42920029347028615 R:0.22595596755504055
cls : chimney|| Recall: 0.7866149369544132 || Precison: 0.08965288525315056|| AP: 0.7260153795479883
F1:0.8302677854462346 P:0.9738903394255874 R:0.7235693501454898
cls : dam|| Recall: 0.48698884758364314 || Precison: 0.037632864119505886|| AP: 0.22475777455839557
F1:0.32017561039641784 P:0.4068767908309456 R:0.26394052044609667
cls : Expressway-Service-area|| Recall: 0.7576036866359447 || Precison: 0.0641185647425897|| AP: 0.6014938573820269
F1:0.6543681269596724 P:0.7638376383763837 R:0.5723502304147465
cls : Expressway-toll-station|| Recall: 0.5319767441860465 || Precison: 0.037638831756478815|| AP: 0.5114919550911468
F1:0.6080403141860409 P:0.8530183727034121 R:0.47238372093023256
cls : golffield|| Recall: 0.8521739130434782 || Precison: 0.1161688003793267|| AP: 0.7301378385581299
F1:0.7716931492843334 P:0.843298969072165 R:0.711304347826087
cls : groundtrackfield|| Recall: 0.8986737400530505 || Precison: 0.13609705149835302|| AP: 0.7426325981625024
F1:0.7815009446283492 P:0.7784210526315789 R:0.7846153846153846
cls : harbor|| Recall: 0.4528180354267311 || Precison: 0.018657360102973766|| AP: 0.1980027445533883
F1:0.2854274258470031 P:0.2915686933154182 R:0.279549114331723
cls : overpass|| Recall: 0.5331088664421998 || Precison: 0.046839562173355685|| AP: 0.370201433199196
F1:0.4835840708308076 P:0.690625 R:0.3720538720538721
cls : ship|| Recall: 0.6425851190814529 || Precison: 0.3424408566322358|| AP: 0.5458477876839686
F1:0.6205132877008095 P:0.70625362739408 R:0.5533450804297164
cls : stadium|| Recall: 0.8214285714285714 || Precison: 0.09687609687609687|| AP: 0.630913131088649
F1:0.6371491697369425 P:0.6795952782462057 R:0.5997023809523809
cls : storagetank|| Recall: 0.49467060485424424 || Precison: 0.3063058287168341|| AP: 0.4355146014716443
F1:0.5514156065451099 P:0.811377245508982 R:0.41761910877102865
cls : tenniscourt|| Recall: 0.8481547051613781 || Precison: 0.3354519013250027|| AP: 0.7984508106192031
F1:0.8341049402628841 P:0.9127549368727743 R:0.7679422579327251
cls : trainstation|| Recall: 0.5893909626719057 || Precison: 0.03502626970227671|| AP: 0.37610932718296497
F1:0.4617121011644533 P:0.5637393767705382 R:0.39096267190569745
cls : vehicle|| Recall: 0.28614864864864864 || Precison: 0.14650036514586617|| AP: 0.2595760213906295
F1:0.34820945729885955 P:0.6732673267326733 R:0.23483483483483483
cls : windmill|| Recall: 0.6320880587058039 || Precison: 0.21128330917605084|| AP: 0.5269190047101941
F1:0.6269189675949228 P:0.7536299765807962 R:0.5366911274182788
mAP is : 0.5096668526593258
"""

