前提・実現したいこと
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/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。