質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

6542閲覧

__init__() got multiple values for argument 'endpoint'エラー

Rondon7251

総合スコア89

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/05/16 05:37

編集2020/05/16 07:02

CustomvisionのAPIを使用したいです。
以下のプログラムでエラーが出ます。
原因や推察など何かわかる方がいましたら教えてください。
お願いします。
おそらく原因はbase_urlのURLが原因だと思います。
その解決を知っている方は教えてください。

Python

1import glob 2from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient 3 4base_url = "https://fishclassfiction.cognitiveservices.azure.com/" 5projectID = 'a6b4a6be-c80c-4bf1-ab9a-d38ff5bc2e32' 6publish_iteration_name = 'Iteration3' 7prediction_key = 'd1a7f168692047458f0c620b884b8f40' 8 9def testModel(testfiles, fishname): 10 data_count = len(testfiles) 11 true_count = 0 12 13 # 予測用インスタンスの作成 …① 14 predictor = CustomVisionPredictionClient(prediction_key, endpoint=base_url) 15 16 for testfile in testfiles: 17 predicts = {} 18 with open(testfile, mode='rb') as f: 19 # 予測実行 …② 20 results = predictor.classify_image(projectID, publish_iteration_name, f.read()) 21 22 # 予測結果のタグの数だけループ …③ 23 for prediction in results.predictions: 24 # 予測した魚とその確率を紐づけて格納 …④ 25 predicts[prediction.tag_name] = prediction.probability 26 27 # 一番確率の高い魚を予測結果として選択 …⑤ 28 prediction_result = max(predicts, key=predicts.get) 29 30 # 予測結果が合っていれば正解数を増やす 31 if fishname == prediction_result: 32 true_count += 1 33 34 # 正解率の算出 35 accuracy = (true_count / data_count) * 100 36 print('正解率:' + str(accuracy) + '%') 37 38 39# 検証用画像を保存したルートディレクトリパス 40root_dir = 'fishimages/' 41# 検証対象の魚名一覧 42fishnames = ['アイゴ','オニカサゴ','カサゴ','カワハギ','キュウセンベラ', 43 'クサフグ','ソウシハギ','マハゼ','マアジ','マイワシ','ミノカサゴ', 44 'メジナ','メバル'] 45 46for fishname in fishnames: 47 print('****' + fishname + '****') 48 # testデータのリストを取得 49 testfiles = glob.glob(root_dir + fishname + '/test/*') 50 testModel(testfiles, fishname) 51

エラー
アイゴ

TypeError Traceback (most recent call last)
<ipython-input-52-0f0d99c2d038> in <module>
10 # testデータのリストを取得
11 testfiles = glob.glob(root_dir + fishname + '/test/*')
---> 12 testModel(testfiles, fishname)

<ipython-input-51-99095a179497> in testModel(testfiles, fishname)
4
5 # 予測用インスタンスの作成 …①
----> 6 predictor = CustomVisionPredictionClient(prediction_key, endpoint=base_url)
7
8 for testfile in testfiles:

TypeError: init() got multiple values for argument 'endpoint'

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

quickquip

2020/05/16 05:47

実行環境にインストールしているazure関連パッケージ名もしくはインストール方法とバージョン。 あなたがどうやってこのコードを書いたのかまたはどうしてこのコードが動くと思ったのか。 を書きましょう。
guest

回答2

0

ベストアンサー

CustomVisionPredictionClient の説明のページを見ますと、CustomVisionPredictionClient(endpoint, credentials) と書いてありますので、順番が逆だと思います。

predictor = CustomVisionPredictionClient(base_url, prediction_key)

ではないでしょうか?

ちなみに、 TypeError: __init__() got multiple values for argument 'endpoint' というエラーですが、こちらは 'endpoint' に複数の値が渡されているという意味です。元のコードですと、おそらく prediction_key も 'endpoint' であると認識されています。

  • CustomVisionPredictionClient の説明のページ

https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-customvision/azure.cognitiveservices.vision.customvision.prediction.customvisionpredictionclient?view=azure-python

投稿2020/06/08 23:49

kabayan55

総合スコア389

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

5 # 予測用インスタンスの作成 …① ----> 6 predictor = CustomVisionPredictionClient(prediction_key, endpoint=base_url) 7 8 for testfile in testfiles: TypeError: init() got multiple values for argument 'endpoint'

というのがエラーメッセージで

TypeError: init() got multiple values for argument 'endpoint'

[直訳] 型のエラー:引数 'endpoint' は、複数の値を取ります
というのがエラーになった理由です。

質問のプログラムでは、endpointが "https://fishclassfiction.cognitiveservices.azure.com/" という単一の文字列になっています。

しかし、Customvisionのサイトで、CustomVisionPredictionClient Constructors のページを見てみると、argumentにはHTTPの応答メッセージの処理を任せる(delegate)ハンドラー(型は、System.Net.Http.DelegatingHandler)のリストを指定しています。

このことから、CustomVisionPredictionClientの使い方を間違えているのがエラーの原因だと
考えられます。

==
僕はCustomVision APIを使ったことが無いのですが、CustomVisionPredictionClient Constructorsのページから情報を辿るか、"http://zure.ly/ai-intro/cognitive-book"からダウンロードできる ”Microsoft Azure Cognitive Services Book”などの資料を読むとヒントが得られるのではないかと思います。

投稿2020/05/16 09:46

coco_bauer

総合スコア6915

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問