From e860bb72e893eb7efbf7fc5ced8a445f4a7a657d Mon Sep 17 00:00:00 2001 From: Andrew Bagshaw Date: Fri, 19 May 2017 13:42:59 -0700 Subject: [PATCH] Clean up wording Test should be reserved for actually testing (i.e. pytest) - images should be stored in a more intuitively named folder and references to "test" should be changed to "predict" where appropirate. --- .gitignore | 1 + README.md | 18 ++++++++-------- darkflow/net/flow.py | 4 ++-- darkflow/net/framework.py | 20 +++++++++--------- darkflow/net/yolo/__init__.py | 2 +- darkflow/net/yolo/data.py | 2 +- darkflow/net/yolo/{test.py => predict.py} | 2 +- darkflow/net/yolov2/__init__.py | 2 +- darkflow/net/yolov2/data.py | 2 +- darkflow/net/yolov2/{test.py => predict.py} | 2 +- flow | 4 ++-- .../sample_computer.jpg | Bin test/dog.jpg => sample_img/sample_dog.jpg | Bin test/eagle.jpg => sample_img/sample_eagle.jpg | Bin .../sample_giraffe.jpg | Bin .../sample_horses.jpg | Bin .../sample_office.jpg | Bin .../sample_person.jpg | Bin .../sample_scream.jpg | Bin test/test_/.gitignore | 10 --------- 20 files changed, 30 insertions(+), 39 deletions(-) rename darkflow/net/yolo/{test.py => predict.py} (98%) rename darkflow/net/yolov2/{test.py => predict.py} (97%) rename test/2007_000039.jpg => sample_img/sample_computer.jpg (100%) rename test/dog.jpg => sample_img/sample_dog.jpg (100%) rename test/eagle.jpg => sample_img/sample_eagle.jpg (100%) rename test/giraffe.jpg => sample_img/sample_giraffe.jpg (100%) rename test/horses.jpg => sample_img/sample_horses.jpg (100%) rename test/ragged-edge-london-office-6.jpg => sample_img/sample_office.jpg (100%) rename test/person.jpg => sample_img/sample_person.jpg (100%) rename test/scream.jpg => sample_img/sample_scream.jpg (100%) delete mode 100644 test/test_/.gitignore diff --git a/.gitignore b/.gitignore index e593c30ab..495a3d848 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ bin/ # Test data test/*.jpg +!test/sample_*.jpg test/out/*.jpg # Annotated test results diff --git a/README.md b/README.md index 68c9f3810..7885a12b5 100644 --- a/README.md +++ b/README.md @@ -97,16 +97,16 @@ First, let's take a closer look at one of a very useful option `--load` # this will print out which layers are reused, which are initialized ``` -All input images from default folder `test/` are flowed through the net and predictions are put in `test/out/`. We can always specify more parameters for such forward passes, such as detection threshold, batch size, test folder, etc. +All input images from default folder `sample_img/` are flowed through the net and predictions are put in `sample_img/out/`. We can always specify more parameters for such forward passes, such as detection threshold, batch size, images folder, etc. ```bash -# Forward all images in test/ using tiny yolo and 100% GPU usage -./flow --test test/ --model cfg/yolo-tiny.cfg --load bin/yolo-tiny.weights --gpu 1.0 +# Forward all images in sample_img/ using tiny yolo and 100% GPU usage +./flow --imgdir sample_img/ --model cfg/yolo-tiny.cfg --load bin/yolo-tiny.weights --gpu 1.0 ``` -json output can be generated with descriptions of the pixel location of each bounding box and the pixel location. Each prediction is stored in the `test/out` folder by default. An example json array is shown below. +json output can be generated with descriptions of the pixel location of each bounding box and the pixel location. Each prediction is stored in the `sample_img/out` folder by default. An example json array is shown below. ```bash -# Forward all images in test/ using tiny yolo and JSON output. -./flow --test test/ --model cfg/yolo-tiny.cfg --load bin/yolo-tiny.weights --json +# Forward all images in sample_img/ using tiny yolo and JSON output. +./flow --imgdir sample_img/ --model cfg/yolo-tiny.cfg --load bin/yolo-tiny.weights --json ``` JSON output: ```json @@ -189,7 +189,7 @@ options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.1 tfnet = TFNet(options) -imgcv = cv2.imread("./test/dog.jpg") +imgcv = cv2.imread("./sample_img/dog.jpg") result = tfnet.return_predict(imgcv) print(result) ``` @@ -210,8 +210,8 @@ The created `.pb` file can be used to migrate the graph to mobile devices (JAVA Also, darkflow supports loading from a `.pb` and `.meta` file for generating predictions (instead of loading from a `.cfg` and checkpoint or `.weights`). ```bash -## Forward images in test for predictions based on protobuf file -./flow --pbLoad graph-cfg/yolo.pb --metaLoad graph-cfg/yolo.meta --test test/ +## Forward images in sample_img for predictions based on protobuf file +./flow --pbLoad graph-cfg/yolo.pb --metaLoad graph-cfg/yolo.meta --imgdir sample_img/ ``` If you'd like to load a `.pb` and `.meta` file when using `return_predict()` you can set the `"pbLoad"` and `"metaLoad"` options in place of the `"model"` and `"load"` options you would normally set. diff --git a/darkflow/net/flow.py b/darkflow/net/flow.py index a5b8ceb5c..d9eab0bc9 100644 --- a/darkflow/net/flow.py +++ b/darkflow/net/flow.py @@ -97,11 +97,11 @@ def return_predict(self, im): import math def predict(self): - inp_path = self.FLAGS.test + inp_path = self.FLAGS.imgdir all_inps = os.listdir(inp_path) all_inps = [i for i in all_inps if self.framework.is_inp(i)] if not all_inps: - msg = 'Failed to find any test files in {} .' + msg = 'Failed to find any images in {} .' exit('Error: {}'.format(msg.format(inp_path))) batch = min(self.FLAGS.batch, len(all_inps)) diff --git a/darkflow/net/framework.py b/darkflow/net/framework.py index 660a3c8a4..7445ab2b3 100644 --- a/darkflow/net/framework.py +++ b/darkflow/net/framework.py @@ -21,28 +21,28 @@ class YOLO(framework): constructor = yolo.constructor parse = yolo.data.parse shuffle = yolo.data.shuffle - preprocess = yolo.test.preprocess - postprocess = yolo.test.postprocess + preprocess = yolo.predict.preprocess + postprocess = yolo.predict.postprocess loss = yolo.train.loss is_inp = yolo.misc.is_inp profile = yolo.misc.profile _batch = yolo.data._batch - resize_input = yolo.test.resize_input - findboxes = yolo.test.findboxes - process_box = yolo.test.process_box + resize_input = yolo.predict.resize_input + findboxes = yolo.predict.findboxes + process_box = yolo.predict.process_box class YOLOv2(framework): constructor = yolo.constructor parse = yolo.data.parse shuffle = yolov2.data.shuffle - preprocess = yolo.test.preprocess + preprocess = yolo.predict.preprocess loss = yolov2.train.loss is_inp = yolo.misc.is_inp - postprocess = yolov2.test.postprocess + postprocess = yolov2.predict.postprocess _batch = yolov2.data._batch - resize_input = yolo.test.resize_input - findboxes = yolov2.test.findboxes - process_box = yolo.test.process_box + resize_input = yolo.predict.resize_input + findboxes = yolov2.predict.findboxes + process_box = yolo.predict.process_box """ framework factory diff --git a/darkflow/net/yolo/__init__.py b/darkflow/net/yolo/__init__.py index 5c0fde608..1ad7d5447 100644 --- a/darkflow/net/yolo/__init__.py +++ b/darkflow/net/yolo/__init__.py @@ -1,5 +1,5 @@ from . import train -from . import test +from . import predict from . import data from . import misc import numpy as np diff --git a/darkflow/net/yolo/data.py b/darkflow/net/yolo/data.py index 6bb044ce7..989c5a31c 100644 --- a/darkflow/net/yolo/data.py +++ b/darkflow/net/yolo/data.py @@ -1,6 +1,6 @@ from darkflow.utils.pascal_voc_clean_xml import pascal_voc_clean_xml from numpy.random import permutation as perm -from .test import preprocess +from .predict import preprocess # from .misc import show from copy import deepcopy import pickle diff --git a/darkflow/net/yolo/test.py b/darkflow/net/yolo/predict.py similarity index 98% rename from darkflow/net/yolo/test.py rename to darkflow/net/yolo/predict.py index cdfee5c86..f0822f10a 100644 --- a/darkflow/net/yolo/test.py +++ b/darkflow/net/yolo/predict.py @@ -117,7 +117,7 @@ def postprocess(self, net_out, im, save = True): # Removing trailing comma+newline adding json list terminator. textBuff = textBuff[:-2] + "]" - outfolder = os.path.join(self.FLAGS.test, 'out') + outfolder = os.path.join(self.FLAGS.imgdir, 'out') img_name = os.path.join(outfolder, im.split('/')[-1]) if self.FLAGS.json: textFile = os.path.splitext(img_name)[0] + ".json" diff --git a/darkflow/net/yolov2/__init__.py b/darkflow/net/yolov2/__init__.py index 9b1c58bc5..41f89e548 100644 --- a/darkflow/net/yolov2/__init__.py +++ b/darkflow/net/yolov2/__init__.py @@ -1,5 +1,5 @@ from . import train -from . import test +from . import predict from . import data from ..yolo import misc import numpy as np diff --git a/darkflow/net/yolov2/data.py b/darkflow/net/yolov2/data.py index 506a19770..7a7e86b14 100644 --- a/darkflow/net/yolov2/data.py +++ b/darkflow/net/yolov2/data.py @@ -1,6 +1,6 @@ from darkflow.utils.pascal_voc_clean_xml import pascal_voc_clean_xml from numpy.random import permutation as perm -from ..yolo.test import preprocess +from ..yolo.predict import preprocess from ..yolo.data import shuffle from copy import deepcopy import pickle diff --git a/darkflow/net/yolov2/test.py b/darkflow/net/yolov2/predict.py similarity index 97% rename from darkflow/net/yolov2/test.py rename to darkflow/net/yolov2/predict.py index ffc5d55bb..cef67e1d9 100644 --- a/darkflow/net/yolov2/test.py +++ b/darkflow/net/yolov2/predict.py @@ -64,7 +64,7 @@ def postprocess(self, net_out, im, save = True): if not save: return imgcv # Removing trailing comma+newline adding json list terminator. textBuff = textBuff[:-2] + "]" - outfolder = os.path.join(self.FLAGS.test, 'out') + outfolder = os.path.join(self.FLAGS.imgdir, 'out') img_name = os.path.join(outfolder, im.split('/')[-1]) if self.FLAGS.json: textFile = os.path.splitext(img_name)[0] + ".json" diff --git a/flow b/flow index 00be2284a..d7241aafb 100755 --- a/flow +++ b/flow @@ -4,7 +4,7 @@ from darkflow.net.build import TFNet from tensorflow import flags import os -flags.DEFINE_string("test", "./test/", "path to testing directory") +flags.DEFINE_string("imgdir", "./sample_img/", "path to testing directory with images") flags.DEFINE_string("binary", "./bin/", "path to .weights directory") flags.DEFINE_string("config", "./cfg/", "path to .cfg directory") flags.DEFINE_string("dataset", "../pascal/VOCdevkit/IMG/", "path to dataset directory") @@ -39,7 +39,7 @@ def get_dir(dirs): for d in dirs: this = os.path.abspath(os.path.join(os.path.curdir, d)) if not os.path.exists(this): os.makedirs(this) -get_dir([FLAGS.test, FLAGS.binary, FLAGS.backup, os.path.join(FLAGS.test,'out'), FLAGS.summary]) +get_dir([FLAGS.imgdir, FLAGS.binary, FLAGS.backup, os.path.join(FLAGS.imgdir,'out'), FLAGS.summary]) # fix FLAGS.load to appropriate type try: FLAGS.load = int(FLAGS.load) diff --git a/test/2007_000039.jpg b/sample_img/sample_computer.jpg similarity index 100% rename from test/2007_000039.jpg rename to sample_img/sample_computer.jpg diff --git a/test/dog.jpg b/sample_img/sample_dog.jpg similarity index 100% rename from test/dog.jpg rename to sample_img/sample_dog.jpg diff --git a/test/eagle.jpg b/sample_img/sample_eagle.jpg similarity index 100% rename from test/eagle.jpg rename to sample_img/sample_eagle.jpg diff --git a/test/giraffe.jpg b/sample_img/sample_giraffe.jpg similarity index 100% rename from test/giraffe.jpg rename to sample_img/sample_giraffe.jpg diff --git a/test/horses.jpg b/sample_img/sample_horses.jpg similarity index 100% rename from test/horses.jpg rename to sample_img/sample_horses.jpg diff --git a/test/ragged-edge-london-office-6.jpg b/sample_img/sample_office.jpg similarity index 100% rename from test/ragged-edge-london-office-6.jpg rename to sample_img/sample_office.jpg diff --git a/test/person.jpg b/sample_img/sample_person.jpg similarity index 100% rename from test/person.jpg rename to sample_img/sample_person.jpg diff --git a/test/scream.jpg b/sample_img/sample_scream.jpg similarity index 100% rename from test/scream.jpg rename to sample_img/sample_scream.jpg diff --git a/test/test_/.gitignore b/test/test_/.gitignore deleted file mode 100644 index 66415af16..000000000 --- a/test/test_/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -/2007_000039.jpg -/2007_004081.jpg -/2007_004405.jpg -/2007_004517.jpg -/eagle.jpg -/giraffe.jpg -/horses.jpg -/person.jpg -/ragged-edge-london-office-6.jpg -/scream.jpg