You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/01/16 19:51:46 UTC

[GitHub] piiswrong closed pull request #8880: correct usage of bool arguments from command line

piiswrong closed pull request #8880: correct usage of bool arguments from command line
URL: https://github.com/apache/incubator-mxnet/pull/8880
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/example/caffe/caffe_net.py b/example/caffe/caffe_net.py
index 0dc4770a24..0459c901e1 100644
--- a/example/caffe/caffe_net.py
+++ b/example/caffe/caffe_net.py
@@ -77,8 +77,8 @@ def parse_args():
                         help='the cnn to use (mlp | lenet | <path to network json file>')
     parser.add_argument('--caffe-loss', type=int, default=0,
                         help='Use CaffeLoss symbol')
-    parser.add_argument('--caffe-data', type=bool, default=False,
-                        help='Use Caffe input-data layer (True | False)')
+    parser.add_argument('--caffe-data', action='store_true',
+                        help='Use Caffe input-data layer only if specified')
     parser.add_argument('--data-dir', type=str, default='mnist/',
                         help='the input data directory')
     parser.add_argument('--gpus', type=str,
diff --git a/example/cnn_chinese_text_classification/text_cnn.py b/example/cnn_chinese_text_classification/text_cnn.py
index 2a78fd2578..4598a52e66 100644
--- a/example/cnn_chinese_text_classification/text_cnn.py
+++ b/example/cnn_chinese_text_classification/text_cnn.py
@@ -38,8 +38,8 @@
 
 parser = argparse.ArgumentParser(description="CNN for text classification",
                                  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
-parser.add_argument('--pretrained-embedding', type=bool, default=False,
-                    help='use pre-trained word2vec')
+parser.add_argument('--pretrained-embedding', action='store_true',
+                    help='use pre-trained word2vec only if specified')
 parser.add_argument('--num-embed', type=int, default=300,
                     help='embedding layer size')
 parser.add_argument('--gpus', type=str, default='',
diff --git a/example/cnn_text_classification/text_cnn.py b/example/cnn_text_classification/text_cnn.py
index d88a8e6994..9ad9443984 100644
--- a/example/cnn_text_classification/text_cnn.py
+++ b/example/cnn_text_classification/text_cnn.py
@@ -31,8 +31,8 @@
 
 parser = argparse.ArgumentParser(description="CNN for text classification",
                                  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
-parser.add_argument('--pretrained-embedding', type=bool, default=False,
-                    help='use pre-trained word2vec')
+parser.add_argument('--pretrained-embedding', action='store_true',
+                    help='use pre-trained word2vec only if specified')
 parser.add_argument('--num-embed', type=int, default=300,
                     help='embedding layer size')
 parser.add_argument('--gpus', type=str, default='',
diff --git a/example/reinforcement-learning/dqn/dqn_demo.py b/example/reinforcement-learning/dqn/dqn_demo.py
index 750da7a69a..8655d5cb55 100644
--- a/example/reinforcement-learning/dqn/dqn_demo.py
+++ b/example/reinforcement-learning/dqn/dqn_demo.py
@@ -55,8 +55,8 @@ def main():
                         help='Eps of the AdaGrad optimizer')
     parser.add_argument('--clip-gradient', required=False, type=float, default=None,
                         help='Clip threshold of the AdaGrad optimizer')
-    parser.add_argument('--double-q', required=False, type=bool, default=False,
-                        help='Use Double DQN')
+    parser.add_argument('--double-q', action='store_true',
+                        help='Use Double DQN only if specified')
     parser.add_argument('--wd', required=False, type=float, default=0.0,
                         help='Weight of the L2 Regularizer')
     parser.add_argument('-c', '--ctx', required=False, type=str, default='gpu',
diff --git a/example/rnn/bucketing/cudnn_lstm_bucketing.py b/example/rnn/bucketing/cudnn_lstm_bucketing.py
index e9c3237f26..84cfc9d438 100644
--- a/example/rnn/bucketing/cudnn_lstm_bucketing.py
+++ b/example/rnn/bucketing/cudnn_lstm_bucketing.py
@@ -33,8 +33,8 @@
                     help='hidden layer size')
 parser.add_argument('--num-embed', type=int, default=200,
                     help='embedding layer size')
-parser.add_argument('--bidirectional', type=bool, default=False,
-                    help='whether to use bidirectional layers')
+parser.add_argument('--bidirectional', action='store_true',
+                    help='uses bidirectional layers if specified')
 parser.add_argument('--gpus', type=str,
                     help='list of gpus to run, e.g. 0 or 0,2,5. empty means using cpu. ' \
                          'Increase batch size when using multiple gpus for best performance.')
diff --git a/example/ssd/demo.py b/example/ssd/demo.py
index 965f2ecec5..8106eb553a 100644
--- a/example/ssd/demo.py
+++ b/example/ssd/demo.py
@@ -88,10 +88,10 @@ def parse_args():
                         help='object visualize score threshold, default 0.6')
     parser.add_argument('--nms', dest='nms_thresh', type=float, default=0.5,
                         help='non-maximum suppression threshold, default 0.5')
-    parser.add_argument('--force', dest='force_nms', type=bool, default=True,
-                        help='force non-maximum suppression on different class')
-    parser.add_argument('--timer', dest='show_timer', type=bool, default=True,
-                        help='show detection time')
+    parser.add_argument('--no-force', dest='force_nms', action='store_false',
+                        help='dont force non-maximum suppression on different class')
+    parser.add_argument('--no-timer', dest='show_timer', action='store_false',
+                        help='dont show detection time')
     parser.add_argument('--deploy', dest='deploy_net', action='store_true', default=False,
                         help='Load network from json file, rather than from symbol')
     parser.add_argument('--class-names', dest='class_names', type=str,
diff --git a/example/ssd/deploy.py b/example/ssd/deploy.py
index a20e8a7816..5c435f4939 100644
--- a/example/ssd/deploy.py
+++ b/example/ssd/deploy.py
@@ -38,8 +38,8 @@ def parse_args():
                         default=20, type=int)
     parser.add_argument('--nms', dest='nms_thresh', type=float, default=0.5,
                         help='non-maximum suppression threshold, default 0.5')
-    parser.add_argument('--force', dest='force_nms', type=bool, default=True,
-                        help='force non-maximum suppression on different class')
+    parser.add_argument('--no-force', dest='force_nms', action='store_false',
+                        help='dont force non-maximum suppression on different class')
     parser.add_argument('--topk', dest='nms_topk', type=int, default=400,
                         help='apply nms only to top k detections based on scores.')
     args = parser.parse_args()
diff --git a/example/ssd/evaluate.py b/example/ssd/evaluate.py
index 4e7f0a4b91..d1a83cca34 100644
--- a/example/ssd/evaluate.py
+++ b/example/ssd/evaluate.py
@@ -59,12 +59,12 @@ def parse_args():
                         help='non-maximum suppression threshold')
     parser.add_argument('--overlap', dest='overlap_thresh', type=float, default=0.5,
                         help='evaluation overlap threshold')
-    parser.add_argument('--force', dest='force_nms', type=bool, default=False,
+    parser.add_argument('--force', dest='force_nms', action='store_true',
                         help='force non-maximum suppression on different class')
-    parser.add_argument('--use-difficult', dest='use_difficult', type=bool, default=False,
+    parser.add_argument('--use-difficult', dest='use_difficult', action='store_true',
                         help='use difficult ground-truths in evaluation')
-    parser.add_argument('--voc07', dest='use_voc07_metric', type=bool, default=True,
-                        help='use PASCAL VOC 07 metric')
+    parser.add_argument('--no-voc07', dest='use_voc07_metric', action='store_false',
+                        help='dont use PASCAL VOC 07 metric')
     parser.add_argument('--deploy', dest='deploy_net', help='Load network from model',
                         action='store_true', default=False)
     args = parser.parse_args()
diff --git a/example/ssd/tools/prepare_dataset.py b/example/ssd/tools/prepare_dataset.py
index 9b4fceb221..6dc95e6fb8 100644
--- a/example/ssd/tools/prepare_dataset.py
+++ b/example/ssd/tools/prepare_dataset.py
@@ -102,8 +102,8 @@ def parse_args():
     parser.add_argument('--root', dest='root_path', help='dataset root path',
                         default=os.path.join(curr_path, '..', 'data', 'VOCdevkit'),
                         type=str)
-    parser.add_argument('--shuffle', dest='shuffle', help='shuffle list',
-                        type=bool, default=True)
+    parser.add_argument('--no-shuffle', dest='shuffle', help='shuffle list',
+                        action='store_false')
     args = parser.parse_args()
     return args
 
diff --git a/example/ssd/train.py b/example/ssd/train.py
index 1648c826c7..1ad70bd4ea 100644
--- a/example/ssd/train.py
+++ b/example/ssd/train.py
@@ -95,12 +95,12 @@ def parse_args():
                         help='non-maximum suppression threshold')
     parser.add_argument('--overlap', dest='overlap_thresh', type=float, default=0.5,
                         help='evaluation overlap threshold')
-    parser.add_argument('--force', dest='force_nms', type=bool, default=False,
+    parser.add_argument('--force', dest='force_nms', action='store_true',
                         help='force non-maximum suppression on different class')
-    parser.add_argument('--use-difficult', dest='use_difficult', type=bool, default=False,
+    parser.add_argument('--use-difficult', dest='use_difficult', action='store_true',
                         help='use difficult ground-truths in evaluation')
-    parser.add_argument('--voc07', dest='use_voc07_metric', type=bool, default=True,
-                        help='use PASCAL VOC 07 11-point metric')
+    parser.add_argument('--no-voc07', dest='use_voc07_metric', action='store_false',
+                        help='dont use PASCAL VOC 07 11-point metric')
     args = parser.parse_args()
     return args
 
diff --git a/tools/im2rec.py b/tools/im2rec.py
index f94c5c0b0a..5547c534d8 100644
--- a/tools/im2rec.py
+++ b/tools/im2rec.py
@@ -211,7 +211,7 @@ def parse_args():
     parser.add_argument('root', help='path to folder containing images.')
 
     cgroup = parser.add_argument_group('Options for creating image lists')
-    cgroup.add_argument('--list', type=bool, default=False,
+    cgroup.add_argument('--list', action='store_true',
                         help='If this is set im2rec will create image list(s) by traversing root folder\
         and output to <prefix>.lst.\
         Otherwise im2rec will read <prefix>.lst and create a database at <prefix>.rec')
@@ -222,20 +222,21 @@ def parse_args():
                         help='Ratio of images to use for training.')
     cgroup.add_argument('--test-ratio', type=float, default=0,
                         help='Ratio of images to use for testing.')
-    cgroup.add_argument('--recursive', type=bool, default=False,
+    cgroup.add_argument('--recursive', action='store_true',
                         help='If true recursively walk through subdirs and assign an unique label\
         to images in each folder. Otherwise only include images in the root folder\
         and give them label 0.')
-    cgroup.add_argument('--shuffle', type=bool, default=True, help='If this is set as True, \
-        im2rec will randomize the image order in <prefix>.lst')
+    cgroup.add_argument('--no-shuffle', dest='shuffle', action='store_false',
+                        help='If this is passed, \
+        im2rec will not randomize the image order in <prefix>.lst')
 
     rgroup = parser.add_argument_group('Options for creating database')
-    rgroup.add_argument('--pass-through', type=bool, default=False,
+    rgroup.add_argument('--pass-through', action='store_true',
                         help='whether to skip transformation and save image as is')
     rgroup.add_argument('--resize', type=int, default=0,
                         help='resize the shorter edge of image to the newsize, original images will\
         be packed by default.')
-    rgroup.add_argument('--center-crop', type=bool, default=False,
+    rgroup.add_argument('--center-crop', action='store_true',
                         help='specify whether to crop the center image to make it rectangular.')
     rgroup.add_argument('--quality', type=int, default=95,
                         help='JPEG quality for encoding, 1-100; or PNG compression for encoding, 1-9')
@@ -250,7 +251,7 @@ def parse_args():
         -1:Loads image as such including alpha channel.')
     rgroup.add_argument('--encoding', type=str, default='.jpg', choices=['.jpg', '.png'],
                         help='specify the encoding of the images.')
-    rgroup.add_argument('--pack-label', type=bool, default=False,
+    rgroup.add_argument('--pack-label', action='store_true',
         help='Whether to also pack multi dimensional label in the record file')
     args = parser.parse_args()
     args.prefix = os.path.abspath(args.prefix)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services