@ -37,8 +37,6 @@ int check_mistakes;
static int coco_ids [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 27 , 28 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 67 , 70 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 84 , 85 , 86 , 87 , 88 , 89 , 90 } ;
float validate_detector_map ( char * datacfg , char * cfgfile , char * weightfile , float thresh_calc_avg_iou , const float iou_thresh , network * existing_net ) ;
void train_detector ( char * datacfg , char * cfgfile , char * weightfile , int * gpus , int ngpus , int clear , int dont_show , int calc_map )
{
list * options = read_data_cfg ( datacfg ) ;
@ -46,20 +44,6 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
char * valid_images = option_find_str ( options , " valid " , train_images ) ;
char * backup_directory = option_find_str ( options , " backup " , " /backup/ " ) ;
int train_images_num = 0 ;
if ( calc_map ) {
FILE * valid_file = fopen ( valid_images , " r " ) ;
if ( ! valid_file ) {
printf ( " \n Error: There is no %s file for mAP calculation! \n Don't use -map flag. \n Or set valid=%s in your %s file. \n " , valid_images , train_images , datacfg ) ;
getchar ( ) ;
exit ( - 1 ) ;
}
else fclose ( valid_file ) ;
list * plist = get_paths ( train_images ) ;
train_images_num = plist - > size ;
free_list ( plist ) ;
}
srand ( time ( 0 ) ) ;
char * base = basecfg ( cfgfile ) ;
printf ( " %s \n " , base ) ;
@ -84,6 +68,43 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
srand ( time ( 0 ) ) ;
network net = nets [ 0 ] ;
int train_images_num = 0 ;
network net_map ;
if ( calc_map ) {
FILE * valid_file = fopen ( valid_images , " r " ) ;
if ( ! valid_file ) {
printf ( " \n Error: There is no %s file for mAP calculation! \n Don't use -map flag. \n Or set valid=%s in your %s file. \n " , valid_images , train_images , datacfg ) ;
getchar ( ) ;
exit ( - 1 ) ;
}
else fclose ( valid_file ) ;
list * plist = get_paths ( train_images ) ;
train_images_num = plist - > size ;
free_list ( plist ) ;
printf ( " Prepare additional network for mAP calculation... \n " ) ;
net_map = parse_network_cfg_custom ( cfgfile , 1 ) ;
int k ;
for ( k = 0 ; k < net . n ; + + k ) {
layer l = net . layers [ k ] ;
if ( l . type = = CONVOLUTIONAL ) {
net_map . layers [ k ] . biases = l . biases ;
net_map . layers [ k ] . scales = l . scales ;
net_map . layers [ k ] . rolling_mean = l . rolling_mean ;
net_map . layers [ k ] . rolling_variance = l . rolling_variance ;
net_map . layers [ k ] . weights = l . weights ;
net_map . layers [ k ] . biases_gpu = l . biases_gpu ;
net_map . layers [ k ] . scales_gpu = l . scales_gpu ;
net_map . layers [ k ] . rolling_mean_gpu = l . rolling_mean_gpu ;
net_map . layers [ k ] . rolling_variance_gpu = l . rolling_variance_gpu ;
net_map . layers [ k ] . weights_gpu = l . weights_gpu ;
net_map . layers [ k ] . weights_gpu16 = l . weights_gpu16 ;
}
}
}
const int actual_batch_size = net . batch * net . subdivisions ;
if ( actual_batch_size = = 1 ) {
printf ( " \n Error: You set incorrect value batch=1 for Training! You should set batch=64 subdivision=64 \n " ) ;
@ -211,7 +232,8 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
# ifdef GPU
if ( ngpus = = 1 ) {
loss = train_network ( net , train ) ;
} else {
}
else {
loss = train_networks ( nets , ngpus , train , 4 ) ;
}
# else
@ -232,21 +254,8 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
int draw_precision = 0 ;
int calc_map_for_each = 4 * train_images_num / ( net . batch * net . subdivisions ) ;
if ( calc_map & & ( i > = ( iter_map + calc_map_for_each ) | | i = = net . max_batches ) & & i > = net . burn_in & & i > = 1000 ) {
if ( l . random ) {
printf ( " Resizing to initial size: %d x %d \n " , init_w , init_h ) ;
args . w = init_w ;
args . h = init_h ;
pthread_join ( load_thread , 0 ) ;
train = buffer ;
load_thread = load_data ( args ) ;
int k ;
for ( k = 0 ; k < ngpus ; + + k ) {
resize_network ( nets + k , init_w , init_h ) ;
}
net = nets [ 0 ] ;
}
iter_map = i ;
mean_average_precision = validate_detector_map ( datacfg , cfgfile , weightfile , 0.25 , 0.5 , & net ) ;
mean_average_precision = validate_detector_map ( datacfg , cfgfile , weightfile , 0.25 , 0.5 , & net_map ) ;
printf ( " \n mean_average_precision = %f \n " , mean_average_precision ) ;
draw_precision = 1 ;
}
@ -632,8 +641,6 @@ float validate_detector_map(char *datacfg, char *cfgfile, char *weightfile, floa
char * train_images = option_find_str ( options , " train " , " data/train.txt " ) ;
char * valid_images = option_find_str ( options , " valid " , train_images ) ;
net = * existing_net ;
initial_batch = net . batch ;
set_batch_network ( & net , 1 ) ;
}
else {
net = parse_network_cfg_custom ( cfgfile , 1 ) ; // set batch=1
@ -970,7 +977,7 @@ float validate_detector_map(char *datacfg, char *cfgfile, char *weightfile, floa
free_list ( options ) ;
if ( existing_net ) {
set_batch_network ( & net , initial_batch ) ;
//set_batch_network(&net, initial_batch);
}
else {
free_network ( net ) ;
@ -1232,7 +1239,8 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
strncpy ( input , filename , 256 ) ;
if ( strlen ( input ) > 0 )
if ( input [ strlen ( input ) - 1 ] = = 0x0d ) input [ strlen ( input ) - 1 ] = 0 ;
} else {
}
else {
printf ( " Enter Image Path: " ) ;
fflush ( stdout ) ;
input = fgets ( input , 256 , stdin ) ;
@ -1368,7 +1376,8 @@ void run_detector(int argc, char **argv)
gpus [ i ] = atoi ( gpu_list ) ;
gpu_list = strchr ( gpu_list , ' , ' ) + 1 ;
}
} else {
}
else {
gpu = gpu_index ;
gpus = & gpu ;
ngpus = 1 ;