Beispiel #1
0
def create_classifier(architecture,
                      labels,
                      input_size,
                      layers,
                      dropout,
                      weights=None,
                      save_bottleneck=False):
    base_model = create_feature_extractor(architecture, input_size, weights)
    x = base_model.feature_extractor.outputs[0]
    x = GlobalAveragePooling2D()(x)
    if len(layers) != 0:
        for layer in layers[0:-1]:
            x = Dense(layer, activation='relu')(x)
            x = Dropout(dropout)(x)
        x = Dense(layers[-1], activation='relu')(x)
    preds = Dense(len(labels), activation='softmax')(x)
    model = Model(inputs=base_model.feature_extractor.inputs[0], outputs=preds)

    bottleneck_layer = None
    if save_bottleneck:
        bottleneck_layer = base_model.feature_extractor.layers[-1].name
    network = Classifier(model, input_size, labels, base_model.normalize,
                         bottleneck_layer)

    return network
Beispiel #2
0
def create_yolo_network(architecture,
                        input_size,
                        nb_classes,
                        nb_box,
                        weights):
    feature_extractor = create_feature_extractor(architecture, input_size, weights)
    yolo_net = YoloNetwork(feature_extractor,
                           input_size,
                           nb_classes,
                           nb_box)
    return yolo_net
Beispiel #3
0
 def representative_dataset_gen(self):
     num_imgs = 10
     from axelerate.networks.common_utils.feature import create_feature_extractor
     backend = create_feature_extractor(self._backend,224)
     image_files_list = glob.glob(self._dataset_path + '/**/*.jpg', recursive=True)
     for filename in image_files_list[0:10]:
         image = cv2.imread(filename)
         image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
         image = cv2.resize(image, (self._img_size, self._img_size))
         data = np.array(backend.normalize(image),dtype=np.float32)
         data = np.expand_dims(data, 0)
     yield [data]
Beispiel #4
0
def create_classifier(architecture, labels, input_size, layers, dropout):
    base_model = create_feature_extractor(architecture, input_size)
    x = base_model.feature_extractor.outputs[0]
    x = GlobalAveragePooling2D()(x)
    for layer in layers[0:-1]:
        x = Dense(layer, activation='relu')(x)
        x = Dropout(dropout)(x)
    x = Dense(layers[-1], activation='relu')(x)
    preds = Dense(len(labels), activation='softmax')(x)
    model = Model(inputs=base_model.feature_extractor.inputs[0], outputs=preds)
    network = Classifier(model, input_size, labels)

    return network
Beispiel #5
0
def squeezenet_segnet(n_classes, input_size, encoder_level, weights):

    encoder = create_feature_extractor('SqueezeNet', input_size, weights)
    encoder_output = encoder.feature_extractor.layers[
        squeezenet[encoder_level]].output
    encoder_input = encoder.feature_extractor.inputs[0]

    model = _segnet(n_classes,
                    encoder_input,
                    encoder_output,
                    input_size,
                    encoder_level=encoder_level)
    model.model_name = "vgg_segnet"
    return model
Beispiel #6
0
def tiny_yolo_segnet(n_classes, input_size, encoder_level, weights):

    encoder = create_feature_extractor('Tiny Yolo', input_size, weights)
    encoder_output = encoder.feature_extractor.layers[
        tiny_yolo[encoder_level]].output
    encoder_input = encoder.feature_extractor.inputs[0]

    model = _segnet(n_classes,
                    encoder_input,
                    encoder_output,
                    input_size,
                    encoder_level=encoder_level)
    model.model_name = "vgg_segnet"
    return model
Beispiel #7
0
def resnet50_segnet(n_classes, input_size, encoder_level, weights):

    encoder = create_feature_extractor('ResNet50', input_size, weights)
    encoder_output = encoder.feature_extractor.layers[
        resnet50[encoder_level]].output
    encoder_input = encoder.feature_extractor.inputs[0]

    model = _segnet(n_classes,
                    encoder_input,
                    encoder_output,
                    input_size,
                    encoder_level=encoder_level)
    model.model_name = "resnet50_segnet"
    return model
Beispiel #8
0
def full_yolo_segnet(n_classes, input_size=224, encoder_level=3):

    encoder = create_feature_extractor('Full Yolo', input_size)
    encoder_output = encoder.feature_extractor.layers[
        full_yolo[encoder_level]].output
    encoder_input = encoder.feature_extractor.inputs[0]

    model = _segnet(n_classes,
                    encoder_input,
                    encoder_output,
                    input_size,
                    encoder_level=encoder_level)
    model.model_name = "vgg_segnet"
    return model
Beispiel #9
0
def vgg16_segnet(n_classes, input_size=224, encoder_level=3):

    encoder = create_feature_extractor('VGG16', input_size)
    encoder_output = encoder.feature_extractor.layers[
        vgg16[encoder_level]].output
    encoder_input = encoder.feature_extractor.inputs[0]

    model = _segnet(n_classes,
                    encoder_input,
                    encoder_output,
                    input_size,
                    encoder_level=encoder_level)
    model.model_name = "vgg_segnet"
    return model
Beispiel #10
0
def nasnetmobile_segnet(n_classes, input_size, encoder_level, weights):

    encoder = create_feature_extractor('NASNetMobile', input_size, weights)
    encoder_output = encoder.feature_extractor.layers[
        nasnetmobile[encoder_level]].output
    encoder_input = encoder.feature_extractor.inputs[0]

    model = _segnet(n_classes,
                    encoder_input,
                    encoder_output,
                    input_size,
                    encoder_level=encoder_level)
    model.model_name = "nasnetmobile_segnet"
    model.normalize = encoder.normalize
    return model
Beispiel #11
0
def densenet121_segnet(n_classes, input_size, encoder_level, weights):

    encoder = create_feature_extractor('DenseNet121', input_size, weights)
    encoder_output = encoder.feature_extractor.layers[
        densenet121[encoder_level]].output
    encoder_input = encoder.feature_extractor.inputs[0]

    model = _segnet(n_classes,
                    encoder_input,
                    encoder_output,
                    input_size,
                    encoder_level=encoder_level)
    model.model_name = "densenet121_segnet"
    model.normalize = encoder.normalize
    return model
Beispiel #12
0
    def edgetpu_dataset_gen(self):
        num_imgs = None
        image_files_list = []
        from axelerate.networks.common_utils.feature import create_feature_extractor
        backend = create_feature_extractor(self._backend, [self._img_size[0], self._img_size[1]])
        image_search = lambda ext : glob.glob(self._dataset_path + ext, recursive=True)
        for ext in ['/**/*.jpg', '/**/*.jpeg', '/**/*.png']: image_files_list.extend(image_search(ext))

        for filename in image_files_list[:num_imgs]:
            image = cv2.imread(filename)
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            image = cv2.resize(image, (self._img_size[0], self._img_size[1]))
            data = np.array(backend.normalize(image), dtype=np.float32)
            data = np.expand_dims(data, 0)
            yield [out]
Beispiel #13
0
def tiny_yolo_segnet(n_classes, input_size, encoder_level, weights):

    encoder = create_feature_extractor('Tiny Yolo', input_size, weights)
    encoder_output = encoder.feature_extractor.layers[
        tiny_yolo[encoder_level]].output
    print(encoder_output)
    encoder_input = encoder.feature_extractor.inputs[0]
    encoder_level += 1
    model = _segnet(n_classes,
                    encoder_input,
                    encoder_output,
                    input_size,
                    encoder_level=encoder_level)
    model.model_name = "tiny_yolo_segnet"
    model.normalize = encoder.normalize
    return model
Beispiel #14
0
def mobilenet_segnet(n_classes,
                     input_size=224,
                     encoder_level=3,
                     architecture='MobileNet2_5'):

    encoder = create_feature_extractor(architecture, input_size)
    encoder_output = encoder.feature_extractor.layers[
        mobilenet[encoder_level]].output
    encoder_input = encoder.feature_extractor.inputs[0]

    model = _segnet(n_classes,
                    encoder_input,
                    encoder_output,
                    input_size,
                    encoder_level=encoder_level)
    model.model_name = "mobilenet_segnet"
    return model
Beispiel #15
0
 def k210_dataset_gen(self):
     num_imgs = None
     image_files_list = []
     from axelerate.networks.common_utils.feature import create_feature_extractor
     backend = create_feature_extractor(self._backend, [self._img_size[0], self._img_size[1]])
     image_search = lambda ext : glob.glob(self._dataset_path + ext, recursive=True)
     for ext in ['/**/*.jpg', '/**/*.jpeg', '/**/*.png']: image_files_list.extend(image_search(ext))
     temp_folder = os.path.join(os.path.dirname(__file__),'tmp')
     os.mkdir(temp_folder)
     print(image_files_list)
     for filename in image_files_list[:num_imgs]:
         image = cv2.imread(filename)
         image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
         image = cv2.resize(image, (self._img_size[0], self._img_size[1]))
         data = np.array(backend.normalize(image), dtype=np.float32)
         data = np.expand_dims(data, 0)
         bin_filename = os.path.basename(filename).split('.')[0]+'.bin'
         with open(os.path.join(temp_folder, bin_filename), "wb") as f: 
             data = np.transpose(data, [0, 3, 1, 2])
             data.tofile(f)
     return temp_folder