resnet_settings = [[5, 5, 20], [2, [1, 1]], [8, [2, 2]]] total_classes = 2 output_path = 'output' nsm_iou_threshold = 0.1 nsm_score_threshold = 0.9 nsm_max_output_size = 500 total_test_examples = 100 abox4d = genanchors(isize=ishape[:2], ssize=ssize, asizes=asizes) abox_4dtensor = tf.constant(value=abox4d, dtype='float32') abox_2dtensor = tf.reshape(tensor=abox_4dtensor, shape=[-1, 4]) model = build_infer_model(ishape=ishape, resnet_settings=resnet_settings, k=len(asizes), total_classes=total_classes, abox_2dtensor=abox_2dtensor, nsm_iou_threshold=nsm_iou_threshold, nsm_score_threshold=nsm_score_threshold, nsm_max_output_size=nsm_max_output_size) model.summary() # model.load_weights('{}/weights.h5'.format(output_path), by_name=True) gen = genx(anno_file_path=test_anno_file_path, image_dir=test_image_dir, ishape=ishape, mode='test') for batch in range(total_test_examples): batchx_4dtensor, _, image_id = next(gen) print('{}: 1'.format(datetime.now().time()), end='\n') boxclz_2dtensor, valid_outputs = model.predict_on_batch(
asizes=asizes[0]) # (h1 * w1 * k1, 4) a2box2d = genanchors(isize=ishape[:2], ssize=ssizes[1], asizes=asizes[1]) # (h2 * w2 * k2, 4) a3box2d = genanchors(isize=ishape[:2], ssize=ssizes[2], asizes=asizes[2]) # (h3 * w3 * k3, 4) abox2d = np.concatenate([a1box2d, a2box2d, a3box2d], axis=0) # (h1*w1*k1 + h2*w2*k2 + h3*w3*k3, 4) abox_2dtensor = tf.constant( value=abox2d, dtype='float32') # (h1*w1*k1 + h2*w2*k2 + h3*w3*k3, 4) model = build_infer_model(ishape=ishape, resnet_settings=resnet_settings, top_down_pyramid_size=top_down_pyramid_size, k=[len(asizes[0]), len(asizes[1]), len(asizes[2])], total_classes=total_classes, abox_2dtensor=abox_2dtensor, nsm_iou_threshold=nsm_iou_threshold, nsm_score_threshold=nsm_score_threshold, nsm_max_output_size=nsm_max_output_size) # model.summary() model.load_weights('{}/weights_best_precision.h5'.format(output_path), by_name=True) model.save('{}/model'.format(output_path)) converter = tf.lite.TFLiteConverter.from_saved_model( '{}/model'.format(output_path)) # converter.optimizations = [tf.lite.Optimize.DEFAULT] converter.experimental_new_converter = True # converter.allow_custom_ops=True