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

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

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

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

2回答

3785閲覧

Pythonでパスを通したい

t-drop

総合スコア12

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2019/07/05 10:26

前提・実現したいこと

https://mementoo.info/archives/2785
こちらのサイトを参考にJupyter notebookを利用して実装しようとしています.

発生している問題・エラーメッセージ

usage: ipykernel_launcher.py [-h] model_path image_paths ipykernel_launcher.py: error: the following arguments are required: image_paths An exception has occurred, use %tb to see the full traceback. SystemExit: 2

image_pathsが指定されていない.

該当のソースコード

Python

1import argparse 2import os 3import numpy as np 4import tensorflow as tf 5from matplotlib import pyplot as plt 6from PIL import Image 7 8os.chdir("C:*****\FCRN-DepthPrediction\tensorflow") 9#モデルのパス指定 10 11import models 12 13def predict(model_data_path, image_path): 14 15 # Default input size 16 height = 228 17 width = 304 18 channels = 3 19 batch_size = 1 20 21 # Read image 22 23 img = Image.open(image_path) 24 img = img.resize([width,height], Image.ANTIALIAS) 25 img = np.array(img).astype('float32') 26 img = np.expand_dims(np.asarray(img), axis = 0) 27 # Create a placeholder for the input image 28 29 input_node = tf.placeholder(tf.float32, shape=(None, height, width, channels)) 30 # Construct the network 31 32 net = models.ResNet50UpProj({'data': input_node}, batch_size, 1, False) 33 with tf.Session() as sess: 34 35 # Load the converted parameters 36 print('Loading the model') 37 38 # Use to load from ckpt file 39 40 saver = tf.train.Saver() 41 saver.restore(sess, model_data_path) 42 43 # Use to load from npy file 44 45 #net.load(model_data_path, sess) 46 47 # Evalute the network for the given image 48 49 # Plot result 50 51 fig = plt.figure() 52 ii = plt.imshow(pred[0,:,:,0], interpolation='nearest') 53 fig.colorbar(ii) 54 plt.show() 55 56 return pred 57 58def main(): 59 # Parse arguments 60 61 parser = argparse.ArgumentParser() 62 parser.add_argument('model_path', help='Converted parameters for the model') 63 parser.add_argument('image_paths', help='Directory of images to predict') 64 args = parser.parse_args() 65 66 # Predict the image 67 68 pred = predict(args.model_path, args.image_paths) 69 70 os._exit(0) 71 72if __name__ == '__main__': 73 74 main() 75 76

試したこと

modelのパス指定まではできたのですが, 参考サイトでいうところの画像パスが通せません.
単純に画像データがあるディレクトリへのpathを通せば良いわけではなさそうで, 詰まってしまいました.

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

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

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

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

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

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

guest

回答2

0

img = Image.open(r"sample.png")
このようにパスを通してあげてみてください

投稿2019/07/05 12:13

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

0

args.image_pathsを画像のパスに置き換えれば動きそうです。

投稿2019/07/05 11:58

mistn

総合スコア1191

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問