import json
import argparse


def create_label_json_file(json_fn):
    labels = create_readable_names_for_imagenet_labels()

    with open(json_fn, 'w') as f:
        json.dump(labels, f,
                  sort_keys=True,
                  indent=4,
                  separators=(',', ': '))

    return labels

logger = get_logger(name="freeze_mobilenet", level='debug')


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-ckpt', '--checkpoint-path', dest='checkpoint_path',
                        default='',
                        help="Path to directory with the checkpoints of the MobileNet model")
    args = parser.parse_args()

    #checkpoint_path = args.checkpoint_path
    checkpoint_path = '/home/leeandro04/Escritorio/NEW_mobilenet_v1_1.0_224_2017_06_14'

    if checkpoint_path == '':
        # Then we have to download a default model
        checkpoint_path = '/tmp/mobilenet'
Exemplo n.º 2
0
"""Adapted from https://github.com/tensorflow/models/blob/master/research/slim/datasets/imagenet.py"""

from mobilenet.fileio import load_json_as_dict, save_dict_as_json, get_logger
from mobilenet.paths import paths

from six.moves import urllib

import os
import re

NUM_CLASSES = 1001
DATA_BASE_URL = 'https://raw.githubusercontent.com/tensorflow/models/master/research/inception/inception/data/'
SYNSET_URL = '{}/imagenet_lsvrc_2015_synsets.txt'.format(DATA_BASE_URL)
SYNSET_TO_HUMAN_URL = '{}/imagenet_metadata.txt'.format(DATA_BASE_URL)

logger = get_logger(name=__name__, level='debug')


def create_readable_names_for_imagenet_labels():
    """Create a dict mapping label id to human readable string.
    Returns:
      labels_to_names: dictionary where keys are integers from to 1000
      and values are human-readable names.
    We retrieve a synset file, which contains a list of valid synset labels used
    by ILSVRC competition. There is one synset one per line, eg.
          #   n01440764
          #   n01443537
    We also retrieve a synset_to_human_file, which contains a mapping from synsets
    to human-readable names for every synset in Imagenet. These are stored in a
    tsv format, as follows:
          #   n02119247    black fox
from __future__ import print_function
"""Script to convert a model in Protobuf format into a one in TFLite format"""

from mobilenet.core import MobileNetV1Restored
from mobilenet.fileio import get_logger

import os
import argparse

logger = get_logger(name="make_inferences", level='debug')

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-pb',
        '--pb-path',
        dest='pb_path',  #required=True,
        help=
        "Path to inference graph in Protobuf format (i.e. file ending with .pb)"
    )
    parser.add_argument(
        '-out',
        '--out-fn',
        dest='output_filename',  #required=True,
        help="Path to output filename for the resulting model converted")
    args = parser.parse_args()

    pb_path = args.pb_path
    output_filename = args.output_filename

    if not os.path.exists(pb_path):