2017-05-07 15 views
0

Pythonを使用してイメージを分類するgithubからコードを実行しようとしていますが、エラーが発生しています。ここPythonエラー:引数の1つが必要です

はコードです:

import argparse as ap 
import cv2 
import imutils 
import numpy as np 
import os 
from sklearn.svm import LinearSVC 
from sklearn.externals import joblib 
from scipy.cluster.vq import * 



# Get the path of the testing set 
parser = ap.ArgumentParser() 
group = parser.add_mutually_exclusive_group(required=True) 
group.add_argument("-t", "--testingSet", help="Path to testing Set") 
group.add_argument("-i", "--image", help="Path to image") 
parser.add_argument('-v',"--visualize", action='store_true') 
args = vars(parser.parse_args()) 

# Get the path of the testing image(s) and store them in a list 
image_paths = [] 
if args["testingSet"]: 
    test_path = args["testingSet"] 
    try: 
     testing_names = os.listdir(test_path) 
    except OSError: 
     print "No such directory {}\nCheck if the file exists".format(test_path) 
     exit() 
for testing_name in testing_names: 
     dir = os.path.join(test_path, testing_name) 
     class_path = imutils.imlist(dir) 
     image_paths+=class_path 
    else: 
     image_paths = [args["image"]] 

、これは私が

usage: getClass.py [-h] 
       (- C:/Users/Lenovo/Downloads/iris/bag-of-words-master/dataset/test TESTINGSET | - C:/Users/Lenovo/Downloads/iris/bag-of-words-master/dataset/test/test_1.jpg IMAGE) 
       [- C:/Users/Lenovo/Downloads/iris/bag-of-words-master/dataset] 
getClass.py: error: one of the arguments - C:/Users/Lenovo/Downloads/iris/bag-of-words-master/dataset/test/--testingSet - C:/Users/Lenovo/Downloads/iris/bag-of-words-master/dataset/test/test_1.jpg/--image is required 

を得ているエラーメッセージであるあなたはこれで私を助けてくださいことができますか?どこに、どのようにファイルパスを書き込むべきですか?

+0

試したコマンドはなんですか? –

答えて

0

これはあなたのプログラムが発行しているエラーです。メッセージはファイルパスではなく、引数の数に関するものです。

group = parser.add_mutually_exclusive_group(required=True) 

このラインはあなたのコマンドライン引数(-t-i)の一方のみが許可されていることを述べています。ただし、コマンドラインに--testingSet--imageの両方を指定しているというエラーメッセージが表示されます。

引数が3つしかないので、引数グループが本当に必要かどうか疑問に思っています。

コマンドラインを機能させるには、相互排他的なグループを削除し、引数をパーサーに直接追加します。

parser.add_argument("-t", "--testingSet", help="Path to testing Set") 
parser.add_argument("-i", "--image", help="Path to image") 
parser.add_argument('-v',"--visualize", action='store_true') 
関連する問題