# -*- 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 = 1
OMEGA = 10

VERSION = 'RetinaNet_DIOR_R_CSL_2x_20211104'

"""
FLOPs: 670629628;    Trainable params: 32926851
cls : airplane|| Recall: 0.6330979055041402 || Precison: 0.3127970639552374|| AP: 0.5725309031911968
F1:0.6491365887856386 P:0.8509083728278041 R:0.5247199220652703
cls : airport|| Recall: 0.5555555555555556 || Precison: 0.02605450320399972|| AP: 0.2635380421578935
F1:0.3775537571857136 P:0.38131699846860645 R:0.3738738738738739
cls : baseballfield|| Recall: 0.7466511357018055 || Precison: 0.24342542485521693|| AP: 0.6760379563584675
F1:0.7352993911439806 P:0.897231543624161 R:0.6228887594641818
cls : basketballcourt|| Recall: 0.8974836905871388 || Precison: 0.13754195529529387|| AP: 0.8016819557266133
F1:0.8598080995883302 P:0.9104166666666667 R:0.8145386766076421
cls : bridge|| Recall: 0.3638470451911935 || Precison: 0.03523339317773788|| AP: 0.1909850403705514
F1:0.2974262197351527 P:0.4126113776559287 R:0.23252220934723833
cls : chimney|| Recall: 0.7875848690591658 || Precison: 0.06865065945214745|| AP: 0.7255181838131147
F1:0.817662184662754 P:0.9823129251700681 R:0.7002909796314258
cls : dam|| Recall: 0.5631970260223048 || Precison: 0.02317222392168859|| AP: 0.20543541493521708
F1:0.3194253601916995 P:0.35280898876404493 R:0.29182156133828996
cls : Expressway-Service-area|| Recall: 0.8221198156682028 || Precison: 0.05950633755837225|| AP: 0.652454248338703
F1:0.6874950177792163 P:0.731048805815161 R:0.6488479262672812
cls : Expressway-toll-station|| Recall: 0.6017441860465116 || Precison: 0.047308878985258825|| AP: 0.5310211677672065
F1:0.6316748791185034 P:0.9194444444444444 R:0.4811046511627907
cls : golffield|| Recall: 0.8782608695652174 || Precison: 0.05420199635075668|| AP: 0.7264598535486224
F1:0.7751888638504433 P:0.87527352297593 R:0.6956521739130435
cls : groundtrackfield|| Recall: 0.9204244031830239 || Precison: 0.12407036613272311|| AP: 0.7361274376034194
F1:0.764034159269302 P:0.7426139208813219 R:0.786737400530504
cls : harbor|| Recall: 0.5317230273752013 || Precison: 0.020496840432531752|| AP: 0.2518279248530294
F1:0.33791980032759766 P:0.39316239316239315 R:0.2962962962962963
cls : overpass|| Recall: 0.5471380471380471 || Precison: 0.04936958833358651|| AP: 0.37129641303643823
F1:0.4758413510218564 P:0.5741475019825535 R:0.4062850729517396
cls : ship|| Recall: 0.6880009094526232 || Precison: 0.32057207177381974|| AP: 0.5642892949164292
F1:0.6501974580159767 P:0.7257951520246603 R:0.5888705735235605
cls : stadium|| Recall: 0.8377976190476191 || Precison: 0.10156954717661916|| AP: 0.6356378786839754
F1:0.6428522104990971 P:0.7274436090225563 R:0.5758928571428571
cls : storagetank|| Recall: 0.4916741577843414 || Precison: 0.30331678462025985|| AP: 0.41207188112352183
F1:0.5314439700392662 P:0.7116075276540726 R:0.4240828731646762
cls : tenniscourt|| Recall: 0.871306005719733 || Precison: 0.33088539511791476|| AP: 0.7862161768572944
F1:0.8181897711634115 P:0.8571215510812826 R:0.782650142993327
cls : trainstation|| Recall: 0.6345776031434185 || Precison: 0.04165054803352676|| AP: 0.4082427800814056
F1:0.4698889464658519 P:0.5887573964497042 R:0.39096267190569745
cls : vehicle|| Recall: 0.3039414414414414 || Precison: 0.1229687452540777|| AP: 0.2633761520464329
F1:0.3450490713359005 P:0.6160378268841069 R:0.23963963963963963
cls : windmill|| Recall: 0.6557705136757839 || Precison: 0.15212008666047663|| AP: 0.5247017061033177
F1:0.6162719485552925 P:0.7328735632183908 R:0.5316877918612408
mAP is : 0.5149725205756426
"""


