View the complete args string while using pdb? - python

I need to view the complete string in the Argparse object args.networkModel
Original code is from https://github.com/cmusatyalab/openface/blob/master/demos/classifier.py
I only have access to the pdb in the terminal.
When I try the print(args.networkModel) I get
/home/aanilil/ml/openface/demos/../models/openargs.networkModelface/nn4.small2.v1.t7
Is there a way to Print the complete string?
I have also tried the pprint(args.networkModel)
Where I get the output
*** TypeError: 'module' object is not callable
The original parser is constructed like so
parser = argparse.ArgumentParser()
parser.add_argument(
'--dlibFacePredictor',
type=str,
help="Path to dlib's face predictor.",
default=os.path.join(
dlibModelDir,
"shape_predictor_68_face_landmarks.dat"))
parser.add_argument(
'--networkModel',
type=str,
help="Path to Torch network model.",
default=os.path.join(
openfaceModelDir,
'nn4.small2.v1.t7'))
parser.add_argument('--imgDim', type=int,
help="Default image dimension.", default=96)
parser.add_argument('--cuda', action='store_true')
parser.add_argument('--verbose', action='store_true')
subparsers = parser.add_subparsers(dest='mode', help="Mode")
trainParser = subparsers.add_parser('train',
help="Train a new classifier.")
trainParser.add_argument('--ldaDim', type=int, default=-1)
trainParser.add_argument(
'--classifier',
type=str,
choices=[
'LinearSvm',
'GridSearchSvm',
'GMM',
'RadialSvm',
'DecisionTree',
'GaussianNB',
'DBN'],
help='The type of classifier to use.',
default='LinearSvm')
trainParser.add_argument(
'workDir',
type=str,
help="The input work directory containing 'reps.csv' and 'labels.csv'. Obtained from aligning a directory with 'align-dlib' and getting the representations with 'batch-represent'.")
inferParser = subparsers.add_parser(
'infer', help='Predict who an image contains from a trained classifier.')
inferParser.add_argument(
'classifierModel',
type=str,
help='The Python pickle representing the classifier. This is NOT the Torch network model, which can be set with --networkModel.')
inferParser.add_argument('imgs', type=str, nargs='+',
help="Input image.")
inferParser.add_argument('--multi', help="Infer multiple faces in image",
action="store_true")
args = parser.parse_args()

Related

Loop one scenario in python-behave feature and execute the rest of scenarios

I was looking for the scenario which can be executed based on the files in a folder.
Folder -
test.xml
test1.xml
test2.xml
I've a feature file like:
Feature: Test Feature
Scenario: Test Scenario
Given create XML Files in {Folder}
Then use the {file}
Then Process the xml
It's written in python behave framework. Please suggest.
I tried using the Runner file
def main(Repetitions, Tag_Expression):
parser = argparse.ArgumentParser(
description="Test Runner allowing to run n test scenarios",
formatter_class=RawTextHelpFormatter)
parser.add_argument(
"repetitions", type=int, nargs="?", default=1,
help="Number of repetitions to run some given test/s\n"
+ "(default=1)")
parser.add_argument(
"-n", "--scenario-names", type=str, nargs="+", default=None,
help="Name of the scenario/s to be run 'x' times\n"
+ "(default=None)")
parser.add_argument(
"-f", "--feature-files", type=str, nargs="+", default=None,
help="Name of the behave feature-file/s to be run 'x' times\n"
+ "(default=None)")
parser.add_argument(
"-o", "--output", type=str, default=None,
help="Write output on specified file instead of stdout\n"
+ "(default=None)")
args = parser.parse_args()
runner_scenario_x_times(Repetitions,
Tag_Expression,
args.scenario_names,
args.feature_files,
args.output)
It's executing for only one tag/scenario/feature.

the following arguments are required

I have the Python script . What I'm trying to do is to test this code in colab
The problem is that the initial script requires arguments. They are defined as follows:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Pipeline to train a NN model specified by a YML config")
parser.add_argument("-t", "--tag", nargs="?", type=str, help="Model tag of the experiment", required=True)
parser.add_argument("-c", "--config", nargs="?", type=str, default="syndoc.yml", help="Config file name")
parser.add_argument("-s", "--seed", nargs="?", type=int, default=4321, help="Seed number")
parser.add_argument('-wt', '--with_test', action='store_true', help='Whether to run corresponding Tester')
args = parser.parse_args()
config = coerce_to_path_and_check_exist(CONFIGS_PATH / args.config)
run_dir = MODELS_PATH / args.tag
trainer = Trainer(config, run_dir, seed=args.seed)
trainer.run(seed=args.seed)
the error
usage: trainer.py [-h] -t [TAG] [-c [CONFIG]] [-s [SEED]] [-wt]
trainer.py: error: the following arguments are required: -t/--tag
Arguments are received when you run a program from the command line (shell, bash, cmd) and they enable effecting the program without changing it e.g. my-program -varX 1 vs my-program -varX 2, you are not doing so, so instead you can remove that code and replace args.config, args.tag etc. with variables e.g. config and tag that you define and set to the values you want.
parser = argparse.ArgumentParser(description="Pipeline to train a NN model specified by a YML config")
parser.add_argument("-t", "--tag", nargs="?", type=str, help="Model tag of the experiment", required=True)
parser.add_argument("-c", "--config", nargs="?", type=str, default="syndoc.yml", help="Config file name")
parser.add_argument("-s", "--seed", nargs="?", type=int, default=4321, help="Seed number")
parser.add_argument('-wt', '--with_test', action='store_true', help='Whether to run corresponding Tester')
args = parser.parse_args()
config = coerce_to_path_and_check_exist(CONFIGS_PATH / args.config)
run_dir = MODELS_PATH / args.tag
trainer = Trainer(config, run_dir, seed=args.seed)
trainer.run(seed=args.seed)

Image manipulation dlib argparse.ArgumentParser() problem?

We are working on a project with my friend, but we still haven't gotten through a big problem. We tried many things but could not fix the problem. the problem is related to "argparse.ArgumentParser().
error part :
usage: detect_drowsiness.py [-h] -p SHAPE_PREDICTOR [-a ALARM] [-w WEBCAM]
detect_drowsiness.py: error: the following arguments are required: -p/--shape-predictor
codes part:
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--shape-predictor", required=True,
help="path to facial landmark predictor")
ap.add_argument("-a", "--alarm", type=str, default="",
help="path alarm .WAV file")
ap.add_argument("-w", "--webcam", type=int, default=0,
help="index of webcam on system")
args = vars(ap.parse_args())
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(args["shape_predictor"])
file content: shape_predictor_68_face_landmarks.dat and detect_drowsiness.py(file name)
Why does this problem exist?
If you notice,
ap.add_argument("-p", "--shape-predictor", required=True,
help="path to facial landmark predictor")
-p/--shape-predictor argument is required. So, you should do the following when you run the python file:
python detect_drowsiness.py -p shape_predictor_68_face_landmarks.dat
or
python detect_drowsiness.py --shape-predictor shape_predictor_68_face_landmarks.dat

Python Error: the following arguments are required: -p/--shape-predictor

I'm new to work with python and i want to run this code , but get this error.
code:
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--shape-predictor", required=True, help="path to facial landmark predictor")
ap.add_argument("-v", "--video", type=str, default="", help="path to input video file")
args = vars(ap.parse_args())
enter image description here
usage:
detect_blinks.py [-h] -p SHAPE_PREDICTOR
Error I'm Getting is:
the following arguments are required: -p/--shape-predictor
As the usage says, You need pass the necessary parameter -p/--shape-predictor.
you can just run this scripts as follows:
python detect_blinks.py -p my/path/to/predictor

how to write argparse for jupyter

How can I write this argparse code in jupyter notebook?
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input image")
ap.add_argument("-y", "--yolo", required=True,
help="base path to YOLO directory")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
help="minimum probability to filter weak detections")
ap.add_argument("-t", "--threshold", type=float, default=0.3,
help="threshold when applying non-maxima suppression")
args = vars(ap.parse_args())
In order to execute your jupyter notebook from command line and to pass arguments you can use tools like papermill
The below github link has detailed documentation on how it can be used
https://github.com/nteract/papermill

Categories