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

# CSL
LABEL_TYPE = 0  # {0: gaussian_label, 1: rectangular_label, 2: pulse_label, 3: triangle_label}
RADIUS = 6
OMEGA = 1

VERSION = 'RetinaNet_DIOR_R_CSL_2x_20200912'

"""
gaussian label, omega=1, r=6
FLOPs: 761359510;    Trainable params: 36287541
cls : airplane|| Recall: 0.5645396980029226 || Precison: 0.286296547891064|| AP: 0.49787545463817895
F1:0.5836700104088177 P:0.7740442655935613 R:0.46846078908913785
cls : airport|| Recall: 0.6471471471471472 || Precison: 0.024651109585907115|| AP: 0.2954192905034122
F1:0.4051675237807779 P:0.4757085020242915 R:0.35285285285285284
cls : baseballfield|| Recall: 0.749563191613279 || Precison: 0.24180366369187412|| AP: 0.6651709584971417
F1:0.7258355409563821 P:0.9100087796312555 R:0.6036691904484566
cls : basketballcourt|| Recall: 0.8970177073625349 || Precison: 0.09624037596240376|| AP: 0.8015749144727041
F1:0.8517643833382655 P:0.908179419525066 R:0.8019571295433364
cls : bridge|| Recall: 0.38122827346465815 || Precison: 0.02874617737003058|| AP: 0.1906461251502268
F1:0.2914125918156961 P:0.41155743481324875 R:0.22556971803785245
cls : chimney|| Recall: 0.7885548011639185 || Precison: 0.0448551724137931|| AP: 0.7256189541611885
F1:0.8231319265114733 P:0.9647979139504563 R:0.7177497575169738
cls : dam|| Recall: 0.637546468401487 || Precison: 0.01950747881476426|| AP: 0.2181995597398333
F1:0.327678616764389 P:0.3320610687022901 R:0.32342007434944237
cls : Expressway-Service-area|| Recall: 0.7963133640552995 || Precison: 0.04874746106973595|| AP: 0.6058170328622385
F1:0.6489810419664054 P:0.7446300715990454 R:0.5751152073732719
cls : Expressway-toll-station|| Recall: 0.6046511627906976 || Precison: 0.03176542455711668|| AP: 0.5030989301970406
F1:0.6088587286535126 P:0.9028571428571428 R:0.45930232558139533
cls : golffield|| Recall: 0.8591304347826086 || Precison: 0.04147426748383847|| AP: 0.7108122840653357
F1:0.7643628676683006 P:0.8507462686567164 R:0.6939130434782609
cls : groundtrackfield|| Recall: 0.9183023872679045 || Precison: 0.09267587536138773|| AP: 0.7533507796162583
F1:0.7676135493890249 P:0.7582815734989649 R:0.7771883289124668
cls : harbor|| Recall: 0.5439613526570048 || Precison: 0.01944486017890653|| AP: 0.2231951194389872
F1:0.3236465247560706 P:0.36792452830188677 R:0.28888888888888886
cls : overpass|| Recall: 0.5768799102132436 || Precison: 0.0349244097163241|| AP: 0.3843754251453817
F1:0.47985639318874745 P:0.6293260473588342 R:0.3877665544332211
cls : ship|| Recall: 0.6771158983686694 || Precison: 0.28837192413367385|| AP: 0.5679343976273945
F1:0.6434044469720595 P:0.7195782073813708 R:0.5818223156937419
cls : stadium|| Recall: 0.8392857142857143 || Precison: 0.07237264211471833|| AP: 0.614650640462732
F1:0.6245852156264109 P:0.6952554744525548 R:0.5669642857142857
cls : storagetank|| Recall: 0.4837121698557425 || Precison: 0.32031294291059587|| AP: 0.4210274312115385
F1:0.5297568365526144 P:0.7479313036690086 R:0.41012799109627157
cls : tenniscourt|| Recall: 0.8669481138499251 || Precison: 0.26112637926083926|| AP: 0.793750568412371
F1:0.8260081748155667 P:0.9018375241779497 R:0.761950156611739
cls : trainstation|| Recall: 0.6738703339882122 || Precison: 0.02393579902302861|| AP: 0.3650045005163461
F1:0.421654135549228 P:0.5097493036211699 R:0.35952848722986247
cls : vehicle|| Recall: 0.30123873873873874 || Precison: 0.10164661177960735|| AP: 0.2650903640855629
F1:0.3443372121985175 P:0.6336016096579477 R:0.23641141141141142
cls : windmill|| Recall: 0.6581054036024016 || Precison: 0.10260010400416017|| AP: 0.5020955681175036
F1:0.5867383011418156 P:0.7587301587301587 R:0.4783188792528352
mAP is : 0.5052354149460687

"""


