# -*- 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
ANGLE_WEIGHT = 0.5

# DCL
OMEGA = 180 / 64.
ANGLE_MODE = 0  # {0: BCL, 1: GCL}

VERSION = 'RetinaNet_DIOR_R_DCL_B_2x_20211105'

"""
FLOPs: 663348835;    Trainable params: 32657166

cls : airplane|| Recall: 0.6109352167559668 || Precison: 0.38604185903354876|| AP: 0.5720591684474536
F1:0.6502725865812726 P:0.8456140350877193 R:0.528251339503166
cls : airport|| Recall: 0.5285285285285285 || Precison: 0.03752265216927833|| AP: 0.21505287409881763
F1:0.3485014150597324 P:0.3310810810810811 R:0.36786786786786785
cls : baseballfield|| Recall: 0.7105416423995341 || Precison: 0.37087703298373614|| AP: 0.6734752290719981
F1:0.7498195282880892 P:0.9450841452612931 R:0.6214327315084449
cls : basketballcourt|| Recall: 0.891425908667288 || Precison: 0.13432102232832469|| AP: 0.8067724889314339
F1:0.8694753721771229 P:0.9124423963133641 R:0.8303821062441752
cls : bridge|| Recall: 0.3526458091927385 || Precison: 0.043753294675803904|| AP: 0.18839575531439606
F1:0.28672511557561475 P:0.37093807480073576 R:0.23368095789880264
cls : chimney|| Recall: 0.7992240543161979 || Precison: 0.09097935298664017|| AP: 0.7243211473133442
F1:0.8193391869346761 P:0.9596354166666666 R:0.7148399612027158
cls : dam|| Recall: 0.4628252788104089 || Precison: 0.024726911618669314|| AP: 0.20244355539424405
F1:0.2943277253872711 P:0.289568345323741 R:0.2992565055762082
cls : Expressway-Service-area|| Recall: 0.7889400921658987 || Precison: 0.11404209965361045|| AP: 0.6433294746192524
F1:0.6980985996832434 P:0.7863741339491916 R:0.6276497695852534
cls : Expressway-toll-station|| Recall: 0.5843023255813954 || Precison: 0.058320034817931236|| AP: 0.5148450976196992
F1:0.6236721381748446 P:0.9230769230769231 R:0.47093023255813954
cls : golffield|| Recall: 0.8452173913043478 || Precison: 0.07021092169893095|| AP: 0.7296274631168209
F1:0.7776640318564313 P:0.8901345291479821 R:0.6904347826086956
cls : groundtrackfield|| Recall: 0.8970822281167109 || Precison: 0.14615384615384616|| AP: 0.721782832479772
F1:0.7697300495343169 P:0.7933558558558559 R:0.7474801061007957
cls : harbor|| Recall: 0.5098228663446055 || Precison: 0.0221132623697371|| AP: 0.24133338476627453
F1:0.33269366067183176 P:0.3596556886227545 R:0.30950080515297906
cls : overpass|| Recall: 0.5364758698092031 || Precison: 0.056914925284276954|| AP: 0.37210740340799237
F1:0.4827776274570396 P:0.624777183600713 R:0.39337822671156003
cls : ship|| Recall: 0.668703461604047 || Precison: 0.3347608343055516|| AP: 0.5592920976520575
F1:0.6385148218948011 P:0.7190135582363617 R:0.5742340703688967
cls : stadium|| Recall: 0.8125 || Precison: 0.11041456016177957|| AP: 0.6194286295102832
F1:0.6311140339753174 P:0.7648305084745762 R:0.5372023809523809
cls : storagetank|| Recall: 0.503146269423398 || Precison: 0.3622076361283165|| AP: 0.4749511172745176
F1:0.5695344451518524 P:0.8116584824964359 R:0.4386798510337742
cls : tenniscourt|| Recall: 0.8650415361568841 || Precison: 0.32808222715768814|| AP: 0.8020822635734022
F1:0.8440933259857688 P:0.8878701337742372 R:0.8044396023423669
cls : trainstation|| Recall: 0.6444007858546169 || Precison: 0.04588696138780078|| AP: 0.3981917251226905
F1:0.47006160159223753 P:0.539440203562341 R:0.4165029469548134
cls : vehicle|| Recall: 0.2939189189189189 || Precison: 0.14710026489319733|| AP: 0.2553317959845845
F1:0.3445166119348715 P:0.6025881470367592 R:0.24121621621621622
cls : windmill|| Recall: 0.6551034022681788 || Precison: 0.14947865134332902|| AP: 0.5146533121743432
F1:0.6057876497725747 P:0.7629179331306991 R:0.5023348899266178
mAP is : 0.5114738407936688
"""

