Ejemplo n.º 1
0
def parse_anchor_parameters(config):
    ratios = np.array(
        list(map(float, config['anchor_parameters']['ratios'].split(' '))),
        keras.backend.floatx())
    scales = np.array(
        list(map(float, config['anchor_parameters']['scales'].split(' '))),
        keras.backend.floatx())
    sizes = list(map(int, config['anchor_parameters']['sizes'].split(' ')))
    strides = list(map(int, config['anchor_parameters']['strides'].split(' ')))

    return AnchorParameters(sizes, strides, ratios, scales)
Ejemplo n.º 2
0
def parse_anchor_parameters(config):
    ratios = np.array(
        list(map(float, config['anchor_parameters']['ratios'].split(' '))),
        keras.backend.floatx())
    scales = np.array(
        list(map(float, config['anchor_parameters']['scales'].split(' '))),
        keras.backend.floatx())
    sizes = list(map(int, config['anchor_parameters']['sizes'].split(' ')))
    strides = list(map(int, config['anchor_parameters']['strides'].split(' ')))
    assert (len(sizes) == len(strides)
            ), "sizes and strides should have an equal number of values"

    return AnchorParameters(sizes, strides, ratios, scales)
Ejemplo n.º 3
0
    def __init__(
        self,
        phi=1,
        image_sizes=(512, 640, 768, 896, 1024, 1280, 1408),
        misc_effect=None,
        visual_effect=None,
        batch_size=1,
        group_method="random",  # one of 'none', 'random', 'ratio'
        shuffle_groups=True,
        detect_text=False,
        detect_quadrangle=False,
    ):
        """
        Initialize Generator object.

        Args:
            batch_size: The size of the batches to generate.
            group_method: Determines how images are grouped together (defaults to 'ratio', one of ('none', 'random', 'ratio')).
            shuffle_groups: If True, shuffles the groups each epoch.
            image_sizes:
        """
        self.misc_effect = misc_effect
        self.visual_effect = visual_effect
        self.batch_size = int(batch_size)
        self.group_method = group_method
        self.shuffle_groups = shuffle_groups
        self.detect_text = detect_text
        self.detect_quadrangle = detect_quadrangle
        self.image_size = image_sizes[phi]
        self.groups = None
        self.anchor_parameters = (AnchorParameters.default if
                                  not self.detect_text else AnchorParameters(
                                      ratios=(0.25, 0.5, 1.0, 2.0),
                                      sizes=(16, 32, 64, 128, 256)))
        self.anchors = anchors_for_shape((self.image_size, self.image_size),
                                         anchor_params=self.anchor_parameters)
        self.num_anchors = self.anchor_parameters.num_anchors()

        # Define groups
        self.group_images()

        # Shuffle when initializing
        if self.shuffle_groups:
            random.shuffle(self.groups)
os.environ['CUDA_VISIBLE_DEVICES'] = '0'

phi = 3
weighted_bifpn = False
model_path = 'checkpoints/2020-02-20/csv_02_1.6506_2.5878_w.h5'
image_sizes = (512, 640, 768, 896, 1024, 1280, 1408)
image_size = image_sizes[phi]
# classes = [
#     'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair',
#     'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor',
# ]
classes = ['text']
num_classes = len(classes)
anchor_parameters = AnchorParameters(
    ratios=(0.25, 0.5, 1., 2.),
    sizes=(16, 32, 64, 128, 256))
score_threshold = 0.4
colors = [np.random.randint(0, 256, 3).tolist() for i in range(num_classes)]
model, prediction_model = efficientdet(phi=phi,
                                       weighted_bifpn=weighted_bifpn,
                                       num_classes=num_classes,
                                       num_anchors=anchor_parameters.num_anchors(),
                                       score_threshold=score_threshold,
                                       detect_quadrangle=True,
                                       anchor_parameters=anchor_parameters,
                                       )
prediction_model.load_weights(model_path, by_name=True)

import glob
Ejemplo n.º 5
0
from tensorflow.keras.optimizers import Adam, SGD

from augmentor.color import VisualEffect
from augmentor.misc import MiscEffect
from model import efficientdet
from losses import smooth_l1, focal, smooth_l1_quad
from efficientnet import BASE_WEIGHTS_PATH, WEIGHTS_HASHES
from utils.anchors import AnchorParameters

from generators.ship import ShipGenerator
from eval.common import evaluate
import numpy as np

AnchorParameters.ship = AnchorParameters(
    sizes=[32, 64, 128, 256, 512],
    strides=[8, 16, 32, 64, 128],
    ratios=np.array([0.25, 0.5, 2, 4], keras.backend.floatx()),
    scales=np.array([0.25, 0.5, 0.75, 1.0, 1.25], keras.backend.floatx()),
)


def main():
    phi = 1
    weighted_bifpn = False
    image_sizes = (512, 640, 768, 896, 1024, 1280, 1408)
    image_size = image_sizes[phi]
    score_threshold = 0.9
    nms_threshold = 0.5

    common_args = {
        'batch_size': 1,
        'phi': phi,