# -*- 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 / 5.0
REG_LOSS_MODE = None

VERSION = 'RetinaNet_DIOR_R_2x_20211102'

"""
RetinaNet-H + 180 + theta=atan(sin(theta)/cos(theta)) + 180, sin^2(theta) + cos^2(theta) = 1
[-90, 90]   sin in [-1, 1]   cos in [0, 1]
FLOPs: 661108632;    Trainable params: 32574186

cls : airplane|| Recall: 0.6255479785679493 || Precison: 0.34867304690151363|| AP: 0.5766508522761908
F1:0.6546157705087002 P:0.829998129792407 R:0.5404286410131515
cls : airport|| Recall: 0.5675675675675675 || Precison: 0.03903748838169989|| AP: 0.2847506734669733
F1:0.4101172958190514 P:0.4895833333333333 R:0.35285285285285284
cls : baseballfield|| Recall: 0.7393709959231217 || Precison: 0.33021199115619715|| AP: 0.6864936734341317
F1:0.7480280747332848 P:0.9361050328227571 R:0.6228887594641818
cls : basketballcourt|| Recall: 0.8872320596458527 || Precison: 0.16726697707107088|| AP: 0.8052070588732088
F1:0.8611265340703455 P:0.907589055240062 R:0.8191985088536813
cls : bridge|| Recall: 0.34685206643491695 || Precison: 0.03949683321604504|| AP: 0.19289209468484775
F1:0.30120917208815423 P:0.4198895027624309 R:0.23483970645036695
cls : chimney|| Recall: 0.7875848690591658 || Precison: 0.0748663101604278|| AP: 0.7250614250614251
F1:0.8288039656584371 P:0.9664082687338501 R:0.7255092143549952
cls : dam|| Recall: 0.49070631970260226 || Precison: 0.024021838034576887|| AP: 0.22252168264035244
F1:0.3233111284062519 P:0.36533957845433257 R:0.2899628252788104
cls : Expressway-Service-area|| Recall: 0.7935483870967742 || Precison: 0.07837960855712335|| AP: 0.6416145453486809
F1:0.6945514955935796 P:0.7664071190211346 R:0.6350230414746544
cls : Expressway-toll-station|| Recall: 0.5508720930232558 || Precison: 0.04971143756558237|| AP: 0.5244942350511828
F1:0.6134570603877183 P:0.90625 R:0.4636627906976744
cls : golffield|| Recall: 0.8469565217391304 || Precison: 0.09708931419457735|| AP: 0.7358050699844052
F1:0.776960278215485 P:0.8188824662813102 R:0.7391304347826086
cls : groundtrackfield|| Recall: 0.9039787798408488 || Precison: 0.14699792960662525|| AP: 0.7626036874611272
F1:0.7825583006992319 P:0.7702980472764646 R:0.7952254641909814
cls : harbor|| Recall: 0.46859903381642515 || Precison: 0.025473135033876642|| AP: 0.18594172836226552
F1:0.30320826042452304 P:0.33781645569620256 R:0.2750402576489533
cls : overpass|| Recall: 0.5594837261503928 || Precison: 0.04848985944263411|| AP: 0.39823996673765266
F1:0.4984795390163709 P:0.6234203875315922 R:0.4152637485970819
cls : ship|| Recall: 0.6040754845677258 || Precison: 0.3973862807785069|| AP: 0.5420702146070459
F1:0.6292037847824606 P:0.7529202138190457 R:0.5404138009435571
cls : stadium|| Recall: 0.7872023809523809 || Precison: 0.0919041000694927|| AP: 0.5799773686327867
F1:0.5965720626184867 P:0.6594594594594595 R:0.5446428571428571
cls : storagetank|| Recall: 0.488934549034716 || Precison: 0.3831471604441314|| AP: 0.4350099510937303
F1:0.5615759282867911 P:0.8044224475133711 R:0.43135995890586876
cls : tenniscourt|| Recall: 0.8608198284080076 || Precison: 0.3352426412092283|| AP: 0.7973741540714552
F1:0.8373291280851239 P:0.895594166925225 R:0.7861909301375459
cls : trainstation|| Recall: 0.6208251473477406 || Precison: 0.042772062804547914|| AP: 0.4048582129140933
F1:0.48904637921088007 P:0.6421725239616614 R:0.3948919449901768
cls : vehicle|| Recall: 0.28911411411411414 || Precison: 0.12332079096949804|| AP: 0.25726111869493773
F1:0.3489664672611739 P:0.6544816191656341 R:0.23791291291291292
cls : windmill|| Recall: 0.6420947298198799 || Precison: 0.17294043661845296|| AP: 0.5323815025996684
F1:0.6279563000124299 P:0.7513940520446096 R:0.5393595730486991
mAP is : 0.5145604607998081
"""

