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

import numpy as np

from configs._base_.models.retinanet_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  # r3det only support 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
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_REFINE_STAGE = 1
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.]

# sample
REFINE_IOU_POSITIVE_THRESHOLD = [0.6, 0.7]
REFINE_IOU_NEGATIVE_THRESHOLD = [0.5, 0.6]

# loss
KL_TAU = 1.0
KL_FUNC = 1   # 0: sqrt  1: log

VERSION = 'RetinaNet_DIOR_R_R3Det_KL_2x_20211025'

"""
FLOPs: 1016279931;    Trainable params: 37331706
cls : airplane|| Recall: 0.5611300535801267 || Precison: 0.23457544288332316|| AP: 0.5019679624551685
F1:0.5849299934615582 P:0.860657676839366 R:0.4430102289332684
cls : airport|| Recall: 0.5780780780780781 || Precison: 0.023673368997110006|| AP: 0.3089568495374678
F1:0.3931574890815528 P:0.45634920634920634 R:0.34534534534534533
cls : baseballfield|| Recall: 0.7451951077460687 || Precison: 0.11521837010355696|| AP: 0.6481018078560677
F1:0.7411591254358074 P:0.9575645756457565 R:0.6045428072218987
cls : basketballcourt|| Recall: 0.8881640260950606 || Precison: 0.09177580893682588|| AP: 0.8134337272870412
F1:0.8864160342101934 P:0.9669603524229075 R:0.8182665424044734
cls : bridge|| Recall: 0.3889532638084202 || Precison: 0.046341463414634146|| AP: 0.2627548890805493
F1:0.3361957671520275 P:0.5168269230769231 R:0.24913093858632676
cls : chimney|| Recall: 0.7740058195926285 || Precison: 0.0996379073542265|| AP: 0.726101079859635
F1:0.8275427118197574 P:0.9788079470198675 R:0.7167798254122212
cls : dam|| Recall: 0.587360594795539 || Precison: 0.013425099838558927|| AP: 0.1991451827799239
F1:0.27108504946659806 P:0.2765957446808511 R:0.26579925650557623
cls : Expressway-Service-area|| Recall: 0.8248847926267281 || Precison: 0.0534296459912841|| AP: 0.691835246279385
F1:0.7268095601081391 P:0.8020022246941045 R:0.6645161290322581
cls : Expressway-toll-station|| Recall: 0.5828488372093024 || Precison: 0.04471454058876004|| AP: 0.525616183595512
F1:0.63290696984021 P:0.9587020648967551 R:0.47238372093023256
cls : golffield|| Recall: 0.8521739130434782 || Precison: 0.05424554411601904|| AP: 0.6868784863827213
F1:0.7318440477181588 P:0.8253275109170306 R:0.6573913043478261
cls : groundtrackfield|| Recall: 0.9236074270557029 || Precison: 0.0601506357103372|| AP: 0.7595523639057896
F1:0.7767534213839193 P:0.8160046728971962 R:0.7411140583554376
cls : harbor|| Recall: 0.557487922705314 || Precison: 0.02969379878205678|| AP: 0.3773908920071199
F1:0.45134284449032525 P:0.6247152619589977 R:0.3533011272141707
cls : overpass|| Recall: 0.6133557800224467 || Precison: 0.03895502174068002|| AP: 0.4979264937474886
F1:0.5726730407600478 P:0.8161993769470405 R:0.44107744107744107
cls : ship|| Recall: 0.7906553742965953 || Precison: 0.27871562390422283|| AP: 0.7095647385282086
F1:0.7871729698246135 P:0.8862367044929031 R:0.7080372875575514
cls : stadium|| Recall: 0.8511904761904762 || Precison: 0.048598130841121495|| AP: 0.5901056737303828
F1:0.6077826563446975 P:0.8398950131233596 R:0.47619047619047616
cls : storagetank|| Recall: 0.5487778776593468 || Precison: 0.19679479307380573|| AP: 0.49012443278370943
F1:0.5751599499249426 P:0.8247381466378828 R:0.44154787894353836
cls : tenniscourt|| Recall: 0.8748467928639521 || Precison: 0.18726679104477612|| AP: 0.8119962554923157
F1:0.87035190700765 P:0.9354939721308909 R:0.8137001225657088
cls : trainstation|| Recall: 0.6895874263261297 || Precison: 0.020798767480445603|| AP: 0.40236060787946376
F1:0.4939709061044945 P:0.5051334702258727 R:0.48330058939096265
cls : vehicle|| Recall: 0.3634009009009009 || Precison: 0.0882449455818278|| AP: 0.3340698386338619
F1:0.42172991018256645 P:0.7191458559536735 R:0.29834834834834834
cls : windmill|| Recall: 0.6200800533689126 || Precison: 0.3459892052856877|| AP: 0.515659087120747
F1:0.6131086087823616 P:0.7209197475202885 R:0.5333555703802535
mAP is : 0.542677089947128
"""


