def model_creator(config): opt = config["opt"] hyper_params = config["hyper_params"] ssd_model = get_model(hyper_params) ssd_custom_losses = CustomLoss(hyper_params["neg_pos_ratio"], hyper_params["loc_loss_alpha"]) ssd_model.compile( optimizer=Adam(learning_rate=1e-3), loss=[ssd_custom_losses.loc_loss_fn, ssd_custom_losses.conf_loss_fn]) init_model(ssd_model) if opt.load_weights: ssd_model.load_weights(config["ssd_model_path"]) return ssd_model
img_size = hyper_params["img_size"] # Data pre-processing train_data = train_data.map(lambda x: data_utils.preprocessing( x, img_size, img_size, augmentation.apply)) val_data = val_data.map( lambda x: data_utils.preprocessing(x, img_size, img_size)) data_shapes = data_utils.get_data_shapes() padding_values = data_utils.get_padding_values() train_data = train_data.shuffle(batch_size * 4).padded_batch( batch_size, padded_shapes=data_shapes, padding_values=padding_values) val_data = val_data.padded_batch(batch_size, padded_shapes=data_shapes, padding_values=padding_values) # Setup training model (ssd+vgg) and loss function (location + confidence) ssd_model = get_model(hyper_params) ssd_custom_losses = CustomLoss(hyper_params["neg_pos_ratio"], hyper_params["loc_loss_alpha"]) ssd_model.compile( optimizer=Adam(learning_rate=1e-3), loss=[ssd_custom_losses.loc_loss_fn, ssd_custom_losses.conf_loss_fn]) init_model(ssd_model) ssd_model_path = io_utils.get_model_path(backbone) if load_weights: ssd_model.load_weights(ssd_model_path) ssd_log_path = io_utils.get_log_path(backbone) # We calculate prior boxes for one time and use it for all operations because of the all images are the same sizes prior_boxes = bbox_utils.generate_prior_boxes( hyper_params["feature_map_shapes"], hyper_params["aspect_ratios"]) ssd_train_feed = train_utils.generator(train_data, prior_boxes, hyper_params)