# -*- 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"
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.]
ANGLE_RANGE = 180

# loss
CLS_WEIGHT = 1.0
REG_WEIGHT = 1.0
ANGLE_WEIGHT = 0.5

# DCL
OMEGA = 180 / 256.  
ANGLE_MODE = 0  # {0: BCL, 1: GCL}

VERSION = 'RetinaNet_DIOR_R_DCL_B_2x_20211102'

"""
FLOPs: 664468957;    Trainable params: 32698656
cls : airplane|| Recall: 0.6173891865562592 || Precison: 0.43079276064236555|| AP: 0.5790698845042276
F1:0.6552838327362347 P:0.8503982902661744 R:0.5330004870920604
cls : airport|| Recall: 0.4924924924924925 || Precison: 0.03684565266232307|| AP: 0.18018773463068607
F1:0.32847399463955534 P:0.356140350877193 R:0.3048048048048048
cls : baseballfield|| Recall: 0.7373325567850902 || Precison: 0.28002654280026545|| AP: 0.6845105464182912
F1:0.7548970902912296 P:0.8996776792908945 R:0.6502620850320326
cls : basketballcourt|| Recall: 0.8844361602982292 || Precison: 0.15950920245398773|| AP: 0.8049620493284583
F1:0.8699925366762865 P:0.9323388385721897 R:0.8154706430568499
cls : bridge|| Recall: 0.3422170722286597 || Precison: 0.03981485642385296|| AP: 0.20427145401345845
F1:0.2834151824974893 P:0.364741641337386 R:0.23174971031286212
cls : chimney|| Recall: 0.7924345295829291 || Precison: 0.11230240549828178|| AP: 0.7256303388949414
F1:0.8294780383901049 P:0.9580686149936467 R:0.7313288069835111
cls : dam|| Recall: 0.4888475836431227 || Precison: 0.02297545208351533|| AP: 0.18056386542231773
F1:0.2836085302913812 P:0.32608695652173914 R:0.25092936802973975
cls : Expressway-Service-area|| Recall: 0.7963133640552995 || Precison: 0.08657314629258517|| AP: 0.6383546529981209
F1:0.6874950623979402 P:0.7739331026528259 R:0.6184331797235023
cls : Expressway-toll-station|| Recall: 0.5683139534883721 || Precison: 0.04809939721983024|| AP: 0.5134305538702947
F1:0.6174197015944609 P:0.8858695652173914 R:0.4738372093023256
cls : golffield|| Recall: 0.8347826086956521 || Precison: 0.06967629554362026|| AP: 0.714153453144245
F1:0.7583522595010999 P:0.8411016949152542 R:0.6904347826086956
cls : groundtrackfield|| Recall: 0.906631299734748 || Precison: 0.146418779986292|| AP: 0.7441620359724744
F1:0.7735799070004271 P:0.7863013698630137 R:0.7612732095490716
cls : harbor|| Recall: 0.5053140096618357 || Precison: 0.020971730267994385|| AP: 0.23926658713283844
F1:0.3270552040250916 P:0.3779560810810811 R:0.2882447665056361
cls : overpass|| Recall: 0.5387205387205387 || Precison: 0.049352251696483655|| AP: 0.36011125064970434
F1:0.46527064248497174 P:0.595968448729185 R:0.38159371492704824
cls : ship|| Recall: 0.6669982379355426 || Precison: 0.32694370533413203|| AP: 0.5606501091522282
F1:0.6361723491403205 P:0.7215153372021771 R:0.5688910362075825
cls : stadium|| Recall: 0.8154761904761905 || Precison: 0.10388625592417061|| AP: 0.626958753520135
F1:0.6394991671900403 P:0.7899343544857768 R:0.5372023809523809
cls : storagetank|| Recall: 0.5084114549890844 || Precison: 0.4043096405228758|| AP: 0.48079073157379915
F1:0.5672438057367174 P:0.7751483679525223 R:0.44728393476306666
cls : tenniscourt|| Recall: 0.8604112760452132 || Precison: 0.3121695735955334|| AP: 0.7985838688236562
F1:0.8400067266273182 P:0.9069951050055266 R:0.7822415906305324
cls : trainstation|| Recall: 0.6227897838899804 || Precison: 0.04295975064371866|| AP: 0.3626977038821033
F1:0.442655690678091 P:0.5316804407713499 R:0.3791748526522593
cls : vehicle|| Recall: 0.29305555555555557 || Precison: 0.12492399270329951|| AP: 0.25442177810459576
F1:0.34384725782346254 P:0.6258051729263701 R:0.23704954954954954
cls : windmill|| Recall: 0.6487658438959306 || Precison: 0.16251671122994651|| AP: 0.5178662471456216
F1:0.6179532018458357 P:0.7294598275079437 R:0.5360240160106737
mAP is : 0.5085321799591098
"""

