# -*- 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(','))
LR = 1e-3
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

VERSION = 'RetinaNet_DIOR_R_RSDet_2x_20201128'

"""
RSDet-8p
FLOPs: 662229097;    Trainable params: 32615676

cls : Expressway-Service-area|| Recall: 0.8589861751152074 || Precison: 0.05740330130574033|| AP: 0.7077386868799547
F1:0.7330546132257147 P:0.8273464658169177 R:0.6580645161290323
cls : tenniscourt|| Recall: 0.8789323164918971 || Precison: 0.3033607520564042|| AP: 0.7857012794326934
F1:0.8193770274071432 P:0.8458750181238219 R:0.7944981615143675
cls : windmill|| Recall: 0.6927951967978653 || Precison: 0.13584930342076001|| AP: 0.5286659144596662
F1:0.6188888440654919 P:0.7193990278391516 R:0.543028685790527
cls : Expressway-toll-station|| Recall: 0.625 || Precison: 0.03401898734177215|| AP: 0.5344552347901361
F1:0.6186084650574205 P:0.8308823529411765 R:0.49273255813953487
cls : golffield|| Recall: 0.9060869565217391 || Precison: 0.06413096996553422|| AP: 0.7574888643713931
F1:0.7864028348881296 P:0.8901098901098901 R:0.7043478260869566
cls : harbor|| Recall: 0.5806763285024155 || Precison: 0.023446338704014358|| AP: 0.29782467987141364
F1:0.37752234753283576 P:0.4247181964573269 R:0.3397745571658615
cls : dam|| Recall: 0.6728624535315985 || Precison: 0.02104406464364609|| AP: 0.2691142236145363
F1:0.362026081181577 P:0.44565217391304346 R:0.3048327137546468
cls : trainstation|| Recall: 0.6444007858546169 || Precison: 0.021516662293361324|| AP: 0.3815880593128638
F1:0.4496993516423597 P:0.5654761904761905 R:0.37328094302554027
cls : baseballfield|| Recall: 0.7743156668608038 || Precison: 0.26243584682195026|| AP: 0.6811438546180969
F1:0.7429230938374606 P:0.9455445544554455 R:0.6118229470005824
cls : vehicle|| Recall: 0.3068318318318318 || Precison: 0.13679418951032568|| AP: 0.2672063508440936
F1:0.3553452081061398 P:0.622696502444528 R:0.24861111111111112
cls : stadium|| Recall: 0.8482142857142857 || Precison: 0.07377685736474243|| AP: 0.6276089125330554
F1:0.6325454169113612 P:0.725 R:0.5610119047619048
cls : chimney|| Recall: 0.7730358874878759 || Precison: 0.04247042523713098|| AP: 0.7260324941088926
F1:0.8350750722792715 P:0.9680306905370843 R:0.7342386032977691
cls : airplane|| Recall: 0.6311495372625426 || Precison: 0.35695592286501376|| AP: 0.567026002527116
F1:0.6346504549275178 P:0.8086349924585219 R:0.5222844617632733
cls : ship|| Recall: 0.707923605979651 || Precison: 0.3610889639476393|| AP: 0.6159131184716269
F1:0.669633251073358 P:0.7577269627023728 R:0.5998976865798897
cls : bridge|| Recall: 0.4322132097334878 || Precison: 0.03649349378730066|| AP: 0.25033393470283555
F1:0.33802340126740676 P:0.43087971274685816 R:0.27809965237543455
cls : overpass|| Recall: 0.6307519640852974 || Precison: 0.0517138256268691|| AP: 0.4578515515288977
F1:0.5263468055036801 P:0.6678170836928387 R:0.43434343434343436
cls : groundtrackfield|| Recall: 0.9262599469496021 || Precison: 0.08814175374829623|| AP: 0.7454750733336922
F1:0.753787919975915 P:0.7564102564102564 R:0.7511936339522547
cls : airport|| Recall: 0.6606606606606606 || Precison: 0.026690931149529876|| AP: 0.3422431949515288
F1:0.4727842036814644 P:0.5450980392156862 R:0.4174174174174174
cls : basketballcourt|| Recall: 0.9044734389561976 || Precison: 0.09671632866610194|| AP: 0.8244285852702582
F1:0.8769870555164442 P:0.941711229946524 R:0.820596458527493
cls : storagetank|| Recall: 0.4953555070416506 || Precison: 0.42391383984174663|| AP: 0.4284867911249676
F1:0.5612463042262482 P:0.7862707288854609 R:0.43636830615127775
mAP is : 0.5398163403373859

"""


