예제 #1
0
def run(experiment_id,
        restore_path=None,
        image_size=(None, None),
        image=DEFAULT_INFERENCE_TEST_DATA_IMAGE,
        config_file=None):
    environment.init(experiment_id)

    config = config_util.load_from_experiment()

    if config_file:
        config = config_util.merge(config, config_util.load(config_file))

    config.BATCH_SIZE = 1
    config.NETWORK.BATCH_SIZE = 1
    config.DATASET.BATCH_SIZE = 1

    if list(image_size) != [None, None]:
        config.IMAGE_SIZE = list(image_size)
        config.NETWORK.IMAGE_SIZE = list(image_size)

        # override pre processes image size.
        if config.PRE_PROCESSOR:
            config.PRE_PROCESSOR.set_image_size(image_size)

        # override post processes image size.
        if config.POST_PROCESSOR:
            config.POST_PROCESSOR.set_image_size(image_size)

        print("Override IMAGE_SIZE", config.IMAGE_SIZE)

    executor.init_logging(config)
    config_util.display(config)

    return _export(config, restore_path, image)
예제 #2
0
def run(input_dir, output_dir, experiment_id, config_file, restore_path,
        save_images):
    environment.init(experiment_id)
    config = config_util.load_from_experiment()
    if config_file:
        config = config_util.merge(config, config_util.load(config_file))

    if not os.path.isdir(input_dir):
        raise FileNotFoundError(
            "Input directory not found: '{}'".format(input_dir))

    if restore_path is None:
        restore_file = search_restore_filename(environment.CHECKPOINTS_DIR)
        restore_path = os.path.join(environment.CHECKPOINTS_DIR, restore_file)

    print("Restore from {}".format(restore_path))

    if not os.path.exists("{}.index".format(restore_path)):
        raise FileNotFoundError(
            "Checkpoint file not found: '{}'".format(restore_path))

    print("---- start predict ----")

    _run(input_dir, output_dir, config, restore_path, save_images)

    print("---- end predict ----")
예제 #3
0
def run(experiment_id, restore_path, config_file, bit, unquant_layers):
    if config_file is None and experiment_id is None:
        raise Exception("config_file or experiment_id are required")

    if experiment_id:
        environment.init(experiment_id)
        config = config_util.load_from_experiment()
        if config_file:
            config = config_util.merge(config, config_util.load(config_file))

        if restore_path is None:
            restore_file = executor.search_restore_filename(environment.CHECKPOINTS_DIR)
            restore_path = os.path.join(environment.CHECKPOINTS_DIR, restore_file)

        if not os.path.exists("{}.index".format(restore_path)):
            raise Exception("restore file {} dont exists.".format(restore_path))

    else:
        experiment_id = "profile"
        environment.init(experiment_id)
        config = config_util.load(config_file)

    config.BATCH_SIZE = 1
    config.NETWORK.BATCH_SIZE = 1
    config.DATASET.BATCH_SIZE = 1

    executor.init_logging(config)
    config_util.display(config)

    _profile(config, restore_path, bit, unquant_layers)
예제 #4
0
def test_merge():

    base_config = EasyDict({"a": "aa", "nest": EasyDict({"b": "bb", "c": "cc"}), "d": "dd"})
    override_config = EasyDict({"a": "_a", "nest": EasyDict({"b": "_b"})})

    expected = EasyDict({"a": "_a", "nest": EasyDict({"b": "_b", "c": "cc"}), "d": "dd"})

    config = config_util.merge(base_config, override_config)
    assert config == expected
예제 #5
0
파일: evaluate.py 프로젝트: kainoj/blueoil
def main(config_file, experiment_id, restore_path, output_dir):
    environment.init(experiment_id)

    config = config_util.load_from_experiment()

    if config_file:
        config = config_util.merge(config, config_util.load(config_file))

    executor.init_logging(config)
    config_util.display(config)

    evaluate(config, restore_path, output_dir)
예제 #6
0
def main(network, dataset, config_file, experiment_id, restore_path,
         output_dir):
    environment.init(experiment_id)

    config = config_util.load_from_experiment()

    if config_file:
        config = config_util.merge(config, config_util.load(config_file))

    if network:
        network_class = module_loader.load_network_class(network)
        config.NETWORK_CLASS = network_class
    if dataset:
        dataset_class = module_loader.load_dataset_class(dataset)
        config.DATASET_CLASS = dataset_class

    executor.init_logging(config)
    config_util.display(config)

    evaluate(config, restore_path, output_dir)
예제 #7
0
def _run(config_file, experiment_id, restore_path, image_size, step_size, cpu):

    if experiment_id:
        environment.init(experiment_id)
        config = config_util.load_from_experiment()
        if config_file:
            config = config_util.merge(config, config_util.load(config_file))

        if restore_path is None:
            restore_file = executor.search_restore_filename(
                environment.CHECKPOINTS_DIR)
            restore_path = os.path.join(environment.CHECKPOINTS_DIR,
                                        restore_file)

        if not os.path.exists("{}.index".format(restore_path)):
            raise Exception(
                "restore file {} dont exists.".format(restore_path))

    else:
        experiment_id = "measure_latency"
        environment.init(experiment_id)
        config = config_util.load(config_file)

    config.BATCH_SIZE = 1
    config.NETWORK.BATCH_SIZE = 1
    config.DATASET.BATCH_SIZE = 1

    if list(image_size) != [None, None]:
        config.IMAGE_SIZE = list(image_size)
        config.NETWORK.IMAGE_SIZE = list(image_size)

        # override pre processes image size.
        if config.PRE_PROCESSOR:
            config.PRE_PROCESSOR.set_image_size(image_size)

        # override post processes image size.
        if config.POST_PROCESSOR:
            config.POST_PROCESSOR.set_image_size(image_size)

        print("Override IMAGE_SIZE", config.IMAGE_SIZE)

    executor.init_logging(config)
    config_util.display(config)

    overall_times, only_network_times = _measure_time(config, restore_path,
                                                      step_size)

    overall_times = np.array(overall_times)
    only_network_times = np.array(only_network_times)
    # list of physical_device_desc
    devices = [
        device.physical_device_desc
        for device in device_lib.list_local_devices()
        if device.physical_device_desc
    ]

    message = """
---- measure latency result ----
total number of execution (number of samples): {}
network: {}
use gpu by network: {}
image size: {}
devices: {}

* overall (include pre-post-process which execute on cpu)
total time: {:.4f} msec
latency
   mean (SD=standard deviation): {:.4f} (SD={:.4f}) msec, min: {:.4f} msec, max: {:.4f} msec
FPS
   mean (SD=standard deviation): {:.4f} (SD={:.4f}), min: {:.4f}, max: {:.4f}

* network only (exclude pre-post-process):
total time: {:.4f} msec
latency
   mean (SD=standard deviation): {:.4f} (SD={:.4f}) msec, min: {:.4f} msec, max: {:.4f} msec
FPS
   mean (SD=standard deviation): {:.4f} (SD={:.4f}), min: {:.4f}, max: {:.4f}
---- measure latency result ----
""".format(
        step_size,
        config.NETWORK_CLASS.__name__,
        not cpu,
        config.IMAGE_SIZE,
        devices,
        # overall
        np.sum(overall_times) * 1000,
        # latency
        np.mean(overall_times) * 1000,
        np.std(overall_times) * 1000,
        np.min(overall_times) * 1000,
        np.max(overall_times) * 1000,
        # FPS
        np.mean(1 / overall_times),
        np.std(1 / overall_times),
        np.min(1 / overall_times),
        np.max(1 / overall_times),
        # network only
        np.sum(only_network_times) * 1000,
        # latency
        np.mean(only_network_times) * 1000,
        np.std(only_network_times) * 1000,
        np.min(only_network_times) * 1000,
        np.max(only_network_times) * 1000,
        # FPS
        np.mean(1 / only_network_times),
        np.std(1 / only_network_times),
        np.min(1 / only_network_times),
        np.max(1 / only_network_times),
    )

    print(message)