From 3916fac897c3c0397e9aa15efcdf4490eaa98a45 Mon Sep 17 00:00:00 2001 From: Taketoshi Fujiwara Date: Thu, 13 Feb 2020 15:37:00 +0900 Subject: [PATCH 1/3] Remove blueoil/cmd/predict.py --- blueoil/cmd/predict.py | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 blueoil/cmd/predict.py diff --git a/blueoil/cmd/predict.py b/blueoil/cmd/predict.py deleted file mode 100644 index 4e78b9c45..000000000 --- a/blueoil/cmd/predict.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 The Blueoil Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================= -import os - -from executor.predict import run as run_predict - - -def predict(input, output, experiment_id, checkpoint=None, save_images=True): - """Predict input images.""" - - output_dir = os.environ.get("OUTPUT_DIR", "saved") - - if checkpoint is None: - restore_path = None - else: - restore_path = os.path.join( - output_dir, experiment_id, "checkpoints", checkpoint - ) - - run_predict(input, output, experiment_id, None, restore_path, save_images) From fbe78d5882e0c67f062dff436919c9335ee70444 Mon Sep 17 00:00:00 2001 From: Taketoshi Fujiwara Date: Thu, 13 Feb 2020 15:41:40 +0900 Subject: [PATCH 2/3] Move lmnet/executor/predict.py to blueoil/cmd --- {lmnet/executor => blueoil/cmd}/predict.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {lmnet/executor => blueoil/cmd}/predict.py (100%) diff --git a/lmnet/executor/predict.py b/blueoil/cmd/predict.py similarity index 100% rename from lmnet/executor/predict.py rename to blueoil/cmd/predict.py From d1a48fbce069be5dc40aafded0b937e96a515bf0 Mon Sep 17 00:00:00 2001 From: Taketoshi Fujiwara Date: Thu, 13 Feb 2020 15:47:47 +0900 Subject: [PATCH 3/3] Update blueoil/cmd/predict.py --- blueoil/cmd/main.py | 10 ++++- blueoil/cmd/predict.py | 44 +++------------------- lmnet/tests/executor_tests/test_predict.py | 2 +- tests/e2e/conftest.py | 2 +- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/blueoil/cmd/main.py b/blueoil/cmd/main.py index 45e79f12d..8c8c1a092 100644 --- a/blueoil/cmd/main.py +++ b/blueoil/cmd/main.py @@ -136,6 +136,12 @@ def convert(experiment_id, checkpoint, template, image_size, project_name): help='ID of this experiment.', required=True, ) +@click.option( + '-c', + '--config', + help='Path of config file.', + default=None, +) @click.option( '-p', '--checkpoint', @@ -147,8 +153,8 @@ def convert(experiment_id, checkpoint, template, image_size, project_name): help="Flag of saving images. Default is True.", default=True, ) -def predict(input, output, experiment_id, checkpoint, save_images): - run_predict(input, output, experiment_id, checkpoint, save_images) +def predict(input, output, experiment_id, config, checkpoint, save_images): + run_predict(input, output, experiment_id, config, checkpoint, save_images) click.echo('Result files are created: {}'.format(output)) diff --git a/blueoil/cmd/predict.py b/blueoil/cmd/predict.py index f56cc10b9..9d04be815 100644 --- a/blueoil/cmd/predict.py +++ b/blueoil/cmd/predict.py @@ -157,50 +157,16 @@ def run(input_dir, output_dir, experiment_id, config_file, restore_path, save_im print("---- end predict ----") -@click.command(context_settings=dict(help_option_names=['-h', '--help'])) -@click.option( - "-in", - "--input_dir", - help="Input directory which contains images to make predictions", - required=True -) -@click.option( - "-o", - "--output_dir", - help="Output directory to save a predicted result", - required=True -) -@click.option( - "-i", - "--experiment_id", - help="Experiment id", - required=True -) -@click.option( - "-c", - "--config_file", - help="config file path. override saved experiment config.", -) -@click.option( - "--restore_path", - help="restore ckpt file base path. e.g. saved/experiment/checkpoints/save.ckpt-10001", - default=None, -) -@click.option( - "--save_images/--no_save_images", - help="Flag of saving images. Default is True.", - default=True, -) -def main(input_dir, output_dir, experiment_id, config_file, restore_path, save_images): +def predict(input_dir, output_dir, experiment_id, config_file=None, checkpoint=None, save_images=True): """Make predictions from input dir images by using trained model. Save the predictions npy, json, images results to output dir. npy: `{output_dir}/npy/{batch number}.npy` json: `{output_dir}/json/{batch number}.json` images: `{output_dir}/images/{some type}/{input image file name}` """ + restore_path = None + if checkpoint: + saved_dir = os.environ.get("OUTPUT_DIR", "saved") + restore_path = os.path.join(saved_dir, experiment_id, "checkpoints", checkpoint) run(input_dir, output_dir, experiment_id, config_file, restore_path, save_images) - - -if __name__ == '__main__': - main() diff --git a/lmnet/tests/executor_tests/test_predict.py b/lmnet/tests/executor_tests/test_predict.py index b1ea4adb5..f54084904 100644 --- a/lmnet/tests/executor_tests/test_predict.py +++ b/lmnet/tests/executor_tests/test_predict.py @@ -15,7 +15,7 @@ # ============================================================================= import pytest -from executor.predict import run +from blueoil.cmd.predict import run from executor.train import run as train_run from blueoil.environment import setup_test_environment diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index 17e23b36c..f0d5093d0 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -104,7 +104,7 @@ def run_all_steps(dirs, config_file): # TODO: Remove this setting after blueoil.environment has been refactored. environment._init_flag = False - predict(predict_input_dir, predict_output_dir, experiment_id, checkpoint_name) + predict(predict_input_dir, predict_output_dir, experiment_id, checkpoint=checkpoint_name) assert os.path.exists(os.path.join(predict_output_dir, 'images')) assert os.path.exists(os.path.join(predict_output_dir, 'json', '0.json'))