Skip to content

Commit

Permalink
Clean up wording
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
abagshaw committed May 19, 2017
1 parent 97ffd9e commit e860bb7
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ bin/

# Test data
test/*.jpg
!test/sample_*.jpg
test/out/*.jpg

# Annotated test results
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
```
Expand All @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions darkflow/net/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
20 changes: 10 additions & 10 deletions darkflow/net/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion darkflow/net/yolo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import train
from . import test
from . import predict
from . import data
from . import misc
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion darkflow/net/yolo/data.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion darkflow/net/yolo/test.py → darkflow/net/yolo/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion darkflow/net/yolov2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import train
from . import test
from . import predict
from . import data
from ..yolo import misc
import numpy as np
2 changes: 1 addition & 1 deletion darkflow/net/yolov2/data.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions flow
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
10 changes: 0 additions & 10 deletions test/test_/.gitignore

This file was deleted.

0 comments on commit e860bb7

Please sign in to comment.