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

# loss
CLS_WEIGHT = 1.0
REG_WEIGHT = 1.0 / 5.0
REG_LOSS_MODE = None

VERSION = 'RetinaNet_DIOR_R_2x_20211022'

"""
RetinaNet-H + 90
FLOPs: 844274425;    Trainable params: 32553441
cls : chimney|| Recall: 0.7914645974781765 || Precison: 0.08828302499188576|| AP: 0.7238040993472865
F1:0.819739972866782 P:0.9572538860103627 R:0.7167798254122212
cls : basketballcourt|| Recall: 0.8797763280521901 || Precison: 0.1283567883608675|| AP: 0.8049556268586766
F1:0.8602744662510151 P:0.9258861439312567 R:0.8033550792171482
cls : windmill|| Recall: 0.6177451634422949 || Precison: 0.16376337430365195|| AP: 0.5158905698334117
F1:0.6178658203659174 P:0.7183908045977011 R:0.5420280186791194
cls : stadium|| Recall: 0.8035714285714286 || Precison: 0.1595744680851064|| AP: 0.6364238383670164
F1:0.639325621704184 P:0.7304015296367112 R:0.5684523809523809
cls : baseballfield|| Recall: 0.7172393709959232 || Precison: 0.28619567743434815|| AP: 0.6668677705795502
F1:0.7457109477877183 P:0.9193341869398207 R:0.627256843331392
cls : airplane|| Recall: 0.6105698977106673 || Precison: 0.3725941888979713|| AP: 0.5709531593961121
F1:0.6458998073912059 P:0.8288821060663869 R:0.529103750608865
cls : overpass|| Recall: 0.5230078563411896 || Precison: 0.04855937060386599|| AP: 0.3744428737445402
F1:0.49200813118744147 P:0.6695652173913044 R:0.3888888888888889
cls : tenniscourt|| Recall: 0.8410731308729402 || Precison: 0.32262445802643264|| AP: 0.7956426923086813
F1:0.830843743660501 P:0.9068793297889479 R:0.76658041672341
cls : Expressway-Service-area|| Recall: 0.7769585253456222 || Precison: 0.05505126363220793|| AP: 0.5990412038087449
F1:0.6510123015242765 P:0.75 R:0.5751152073732719
cls : Expressway-toll-station|| Recall: 0.5508720930232558 || Precison: 0.041543351967554536|| AP: 0.5056138865232777
F1:0.620296181841573 P:0.8776595744680851 R:0.4796511627906977
cls : golffield|| Recall: 0.8504347826086956 || Precison: 0.07280035730236713|| AP: 0.7305288745499104
F1:0.7753084634519467 P:0.8701298701298701 R:0.6991304347826087
cls : groundtrackfield|| Recall: 0.8875331564986737 || Precison: 0.16321951219512196|| AP: 0.7318400438478007
F1:0.7716697453802182 P:0.7834882449425916 R:0.7602122015915119
cls : trainstation|| Recall: 0.5343811394891945 || Precison: 0.04486227939963714|| AP: 0.3540045872681856
F1:0.4478325857867968 P:0.6353790613718412 R:0.34577603143418467
cls : bridge|| Recall: 0.32367709540363077 || Precison: 0.046514209591474245|| AP: 0.21000461897335063
F1:0.2917042739240256 P:0.42209217264081933 R:0.22286597141753572
cls : storagetank|| Recall: 0.48563845725782284 || Precison: 0.32538863075775826|| AP: 0.4357359253928568
F1:0.553609048900016 P:0.7888818498574596 R:0.42643722443388554
cls : ship|| Recall: 0.6325527198317513 || Precison: 0.33896317504797296|| AP: 0.5420261659289217
F1:0.6136376758977725 P:0.7081675898732295 R:0.5413800943557097
cls : dam|| Recall: 0.49814126394052044 || Precison: 0.02864471996579735|| AP: 0.17720187562913614
F1:0.317264108640548 P:0.34497816593886466 R:0.2936802973977695
cls : vehicle|| Recall: 0.2821321321321321 || Precison: 0.13597467209407507|| AP: 0.2577300471908954
F1:0.34372695947942505 P:0.6764381750055103 R:0.2304054054054054
cls : harbor|| Recall: 0.4373590982286634 || Precison: 0.019219882246376812|| AP: 0.16098587632547798
F1:0.2662054697323324 P:0.32497678737233054 R:0.22544283413848631
cls : airport|| Recall: 0.5345345345345346 || Precison: 0.04558258642765685|| AP: 0.2885242166078697
F1:0.40364954162189276 P:0.4516728624535316 R:0.36486486486486486
mAP is : 0.5041108976240851
"""

