# -*- 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]

# loss
FAST_RCNN_LOCATION_LOSS_WEIGHT = 1.0
FAST_RCNN_CLASSIFICATION_LOSS_WEIGHT = 1.0

BCD_TAU = 2.0
BCD_FUNC = 0   # 0: sqrt  1: log

VERSION = 'FPN_Res50D_DIOR_R_R2CNN_BCD_2x_20211028'

"""
R2CNN + BCD
FLOPs: 810673122;    Trainable params: 41791120

cls : airplane|| Recall: 0.5963224549439844 || Precison: 0.8812308799712075|| AP: 0.5410423112592799
F1:0.7113548607138218 P:0.8813894888408927 R:0.5963224549439844
cls : airport|| Recall: 0.4369369369369369 || Precison: 0.1514047866805411|| AP: 0.21973678093136662
F1:0.37910206709314415 P:0.43186180422264875 R:0.33783783783783783
cls : baseballfield|| Recall: 0.7166569598136284 || Precison: 0.8353699932111337|| AP: 0.7147826389452049
F1:0.7910823977515213 P:0.9313609467455621 R:0.6875364006988934
cls : basketballcourt|| Recall: 0.8830382106244176 || Precison: 0.768762677484787|| AP: 0.808296712569354
F1:0.8951033088014354 P:0.9368313805399898 R:0.8569431500465983
cls : bridge|| Recall: 0.42255697180378526 || Precison: 0.19729486023444545|| AP: 0.30771038119296823
F1:0.4006535953793686 P:0.5120192307692307 R:0.3290845886442642
cls : chimney|| Recall: 0.7584869059165859 || Precison: 0.7540983606557377|| AP: 0.7244093144532383
F1:0.8247486432430068 P:0.9471698113207547 R:0.7303588748787585
cls : dam|| Recall: 0.4200743494423792 || Precison: 0.12302667392487751|| AP: 0.22245629289288002
F1:0.33018368046015717 P:0.33524904214559387 R:0.3252788104089219
cls : Expressway-Service-area|| Recall: 0.7649769585253456 || Precison: 0.3889409559512652|| AP: 0.6805503403525928
F1:0.7501222809149685 P:0.8375 R:0.6792626728110599
cls : Expressway-toll-station|| Recall: 0.7034883720930233 || Precison: 0.4396003633060854|| AP: 0.6519139572891015
F1:0.7228866216560533 P:0.8078994614003591 R:0.6540697674418605
cls : golffield|| Recall: 0.8173913043478261 || Precison: 0.42152466367713004|| AP: 0.7479591881156157
F1:0.8029828890469686 P:0.8669354838709677 R:0.7478260869565218
cls : groundtrackfield|| Recall: 0.8854111405835544 || Precison: 0.5511889035667107|| AP: 0.7617831096445622
F1:0.7902923410179693 P:0.7773217034376604 R:0.8037135278514589
cls : harbor|| Recall: 0.4650563607085346 || Precison: 0.19419042495965572|| AP: 0.3269167716763817
F1:0.42653734603840515 P:0.5388397246804326 R:0.3529790660225443
cls : overpass|| Recall: 0.5443322109988776 || Precison: 0.27809633027522934|| AP: 0.45529342228263403
F1:0.5482629406481184 P:0.6842989084802686 R:0.45735129068462405
cls : ship|| Recall: 0.8480077303472973 || Precison: 0.8268351483913875|| AP: 0.8011852424795856
F1:0.8668920863922384 P:0.9197168728478511 R:0.8198146990280225
cls : stadium|| Recall: 0.7574404761904762 || Precison: 0.4158496732026144|| AP: 0.6286184841691113
F1:0.6358246631739797 P:0.6275362318840579 R:0.6443452380952381
cls : storagetank|| Recall: 0.747570737554043 || Precison: 0.8374011028530328|| AP: 0.7109654338693516
F1:0.8051163115070709 P:0.9065380493033226 R:0.7241128376353752
cls : tenniscourt|| Recall: 0.8365790548822007 || Precison: 0.8699900863900297|| AP: 0.8075676557108522
F1:0.8743024032795177 P:0.9408441864114232 R:0.8165599891052703
cls : trainstation|| Recall: 0.6444007858546169 || Precison: 0.23597122302158274|| AP: 0.48111350085393423
F1:0.5723287134704645 P:0.6187214611872146 R:0.5324165029469549
cls : vehicle|| Recall: 0.49654654654654656 || Precison: 0.5041734954453634|| AP: 0.43159193180041955
F1:0.5521646105399001 P:0.7601184600197434 R:0.43355855855855857
cls : windmill|| Recall: 0.7498332221480988 || Precison: 0.5793814432989691|| AP: 0.6346954877243843
F1:0.7483821071632727 P:0.7840701497990501 R:0.7158105403602402
mAP is : 0.5829294479106408
"""
