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

import numpy as np

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

# schedule
BATCH_SIZE = 1
GPU_GROUP = "0,1"
NUM_GPU = len(GPU_GROUP.strip().split(','))
LR = 0.001 * BATCH_SIZE * NUM_GPU
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
LEVEL = ['P2', 'P3', 'P4', 'P5', 'P6']
BASE_ANCHOR_SIZE_LIST = [32, 64, 128, 256, 512]
ANCHOR_STRIDE = [4, 8, 16, 32, 64]
ANCHOR_SCALES = [1.0]
ANCHOR_RATIOS = [0.5, 1., 2.0]

VERSION = 'FPN_Res50D_DIOR_R_2x_20211028'

"""
R2CNN
FLOPs: 810673094;    Trainable params: 41791120

cls : airplane|| Recall: 0.6251826595226497 || Precison: 0.8625672043010753|| AP: 0.6235800509823627
F1:0.7252994055408432 P:0.8657094594594594 R:0.6240867023867511
cls : airport|| Recall: 0.5045045045045045 || Precison: 0.15067264573991032|| AP: 0.30208356372659506
F1:0.45028263714116257 P:0.49727767695099817 R:0.4114114114114114
cls : baseballfield|| Recall: 0.7105416423995341 || Precison: 0.8163265306122449|| AP: 0.7113029311871395
F1:0.780812419075651 P:0.9292604501607717 R:0.6732673267326733
cls : basketballcourt|| Recall: 0.8774464119291705 || Precison: 0.7154255319148937|| AP: 0.8061589710371643
F1:0.8876743858055857 P:0.9462025316455697 R:0.8359739049394221
cls : bridge|| Recall: 0.43530320587099264 || Precison: 0.1594510469722694|| AP: 0.29651713189321016
F1:0.3922861491531467 P:0.5324503311258278 R:0.3105446118192352
cls : chimney|| Recall: 0.7575169738118331 || Precison: 0.6238019169329073|| AP: 0.7225619728722995
F1:0.8123571261120468 P:0.942381562099872 R:0.7138700290979632
cls : dam|| Recall: 0.45539033457249073 || Precison: 0.11151570323167956|| AP: 0.22907096364022256
F1:0.33631343298862 P:0.3618843683083512 R:0.3141263940520446
cls : Expressway-Service-area|| Recall: 0.8009216589861751 || Precison: 0.3554192229038855|| AP: 0.7250474209443549
F1:0.7617552904752245 P:0.84417040358767444 R:0.6940092165898617
cls : Expressway-toll-station|| Recall: 0.7107558139534884 || Precison: 0.36574420344053854|| AP: 0.6566390354399606
F1:0.7092388196649292 P:0.8406374501992032 R:0.6133720930232558
cls : golffield|| Recall: 0.8104347826086956 || Precison: 0.4267399267399267|| AP: 0.7353048747769579
F1:0.7870320580733362 P:0.8415841584158416 R:0.7391304347826086
cls : groundtrackfield|| Recall: 0.8811671087533156 || Precison: 0.5490909090909091|| AP: 0.7654654844972199
F1:0.7998866891802517 P:0.816924778761062 R:0.7835543766578249
cls : harbor|| Recall: 0.4247987117552335 || Precison: 0.1376395700720025|| AP: 0.2619457415187728
F1:0.365193036069533 P:0.4344735673034207 R:0.314975845410628
cls : overpass|| Recall: 0.5634118967452301 || Precison: 0.2164259538693684|| AP: 0.45622140596801636
F1:0.5439583979343244 P:0.6548183254344392 R:0.46520763187429853
cls : ship|| Recall: 0.8367816745296425 || Precison: 0.7820393635953146|| AP: 0.7889352098425425
F1:0.8500402400846752 P:0.9050523207292803 R:0.8013414426192236
cls : stadium|| Recall: 0.8005952380952381 || Precison: 0.41770186335403725|| AP: 0.6883008549606149
F1:0.6736117103225863 P:0.7304347826086957 R:0.625
cls : storagetank|| Recall: 0.7599417833140705 || Precison: 0.7976725377426312|| AP: 0.7117629122894152
F1:0.8043757914449415 P:0.8989162040708433 R:0.7278369932793973
cls : tenniscourt|| Recall: 0.8466566798311317 || Precison: 0.8358429685399301|| AP: 0.8094911304370689
F1:0.8785378296411119 P:0.94468818552178 R:0.8210540650960098
cls : trainstation|| Recall: 0.5540275049115914 || Precison: 0.1646234676007005|| AP: 0.3857574309742405
F1:0.49999505179556375 P:0.5566265060240964 R:0.4538310412573674
cls : vehicle|| Recall: 0.5044669669669669 || Precison: 0.4185691593733454|| AP: 0.47042039872794367
F1:0.5454017470026916 P:0.761850255857797 R:0.4247372372372372
cls : windmill|| Recall: 0.7605070046697798 || Precison: 0.5575935436537051|| AP: 0.6350049936383474
F1:0.7591165211952522 P:0.8092900302114804 R:0.7148098732488326
mAP is : 0.5890786239677225
"""
