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

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

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

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

関数

関数(ファンクション・メソッド・サブルーチンとも呼ばれる)は、はプログラムのコードの一部であり、ある特定のタスクを処理するように設計されたものです。

Python

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

Q&A

0回答

971閲覧

IndexError: index 0 is out of bounds for axis 0 with size 0について

tadapolice

総合スコア21

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

関数

関数(ファンクション・メソッド・サブルーチンとも呼ばれる)は、はプログラムのコードの一部であり、ある特定のタスクを処理するように設計されたものです。

Python

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

0グッド

0クリップ

投稿2020/05/31 06:39

画像を読み込む関数,ノイズを付加する関数,画像をsaveする関数を定義し,処理したところ
IndexError: index 0 is out of bounds for axis 0 with size 0 というerrorがでてきました.

testimageに何もないというメッセージというのはわかりますが,原因がわかりません.

#画像を読み込む def load_images(inputhpath,imagesize,type_color): imglist=[] exclude_prefixes=('_','.') for root,dirs,files in os.walk(inputpath): dirs[:]=[dir for dir in dirs if not dir.startswith(exclude_prefixes)] files[:]=[file for file in files if not file.startswith(exclude_prefixes)] for fn in sorted(files): bn,ext=os.path.splitext(fn) if ext not in[".bmp",".BMP",".jpg",".JPG",".jpeg",".JPEG",".png",".PNG"]: continue filename=os.path.join(root,fn) if type_color=='Color': testimage=cv2.imread(filename,cv2.IMREAD_COLOR) height,width=testimage.shape[:2] testimage=cv2.resize(testimage,(imagesize,imagesize),interpolation=cv2.INTER_AREA) testimage=np.asarray(testimage,dtype=np.float64) testimage=testimage[:,:,::,-1] elif type_color=='Gray': testimage=cv2.imread(filename,cv2.IMREAD_GRAYSCALE) height,width=testimage.shape[:2] testimage=cv2.resize(testimage,(imagesize,imagesize),interpolation=cv2.INTER_AREA) testimage=np.asarray([testimage],dtype=np.float64) testimage=np.asarray(testimage,dtype=np.float64).reshape((imagesize,imagesize,1)) imglist.append(testimage) imgsdata=np.asarray(imglist,dtype=np.float32) return imgsdata,sorted(files) inputpath='drive/My Drive/denoise' #ノイズを付加する def generate_noise(imagelist): imagelist_out=[] for i in range(0,len(imagelist)): image_temp=imagelist[i]+np.random.normal(loc=0.0,scale=50.0,size=imagelist[i].shape) image_temp=np.clip(image_temp,0,255) imagelist_out.append(image_temp) imgsdata=np.asarray(imagelist_out,dtype=np.float32) return imgsdata imagelist='drive/My Drive/denoise/train' #画像を保存 def save_images(savepath,filnamelist,imagelist): for i,fn in enumerate(savepath): filename=os.path.join(savepath,fn) testimage=imagelist[i] testimage=testimage[:,:,::-1] cv2.imwrite(filename,testimage) savepath='drive/My Drive/denoise' #処理の実行 image_train,image_train_filenames=load_images("drive/My Drive/denoise/train",256,'Gray') image_test,image_test_filenames=load_images("drive/My Drivet/denoise/test",256,'Gray') image_train=generate_noise(image_train) image_test=generate_noise(image_test) save_images("drive/My Drive/denoise/train_noise",image_train_filenames,image_train) save_images("drive/My Drive/denoise/test_noise",image_test_filenames,image_test) --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-26-077254fccf41> in <module>() 5 image_test=generate_noise(image_test) 6 ----> 7 save_images("drive/My Drive/denoise/train_noise",image_train_filenames,image_train) 8 save_images("drive/My Drive/denoise/test_noise",image_test_filenames,image_test) <ipython-input-25-1c159fb19400> in save_images(savepath, filnamelist, imagelist) 2 for i,fn in enumerate(savepath): 3 filename=os.path.join(savepath,fn) ----> 4 testimage=imagelist[i] 5 testimage=testimage[:,:,::-1] 6 cv2.imwrite(filename,testimage) IndexError: index 0 is out of bounds for axis 0 with size 0

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

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

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

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

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

meg_

2020/05/31 08:51

image_trainの中身を追っていったらどうなっていますか?(load_images()の前後、generate_noise()の前後で確認するなど)
tadapolice

2020/05/31 11:55

勉強不足ですみません. save_imageの前にimge_trainの中身を確認できますか?
tadapolice

2020/05/31 11:57

array([], dtype=float32) とでできました.
meg_

2020/05/31 12:02

それはどの状態のデータでしょうか? まず「load_images("drive/My Drive/denoise/train",256,'Gray')」でちゃんと「image_train」に読み込めてますか? 読み込めているなら「generate_noise(image_train)」でデータが消失しているのでしょう。
tadapolice

2020/05/31 12:04

load_images("drive/My Drive/denoise/train",256,'Gray') のあとに image_train で array([], dtype=float32)となりました. 画像が読み込めていないということでしょうか?
meg_

2020/05/31 12:15

そうだと思います。ただ、load_images()のどこでそれが起きているのかは分かりません。
tadapolice

2020/05/31 12:16

ありがとうございます. 元データを再度確認してみます.
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問