看板 Python 關於我們 聯絡資訊
各位前輩好 小的最近在建構CNN時遇到一些問題 當我讀進訓練集N張照片時train.shape會顯示(N,1) train[0][0].shape就會顯示(height ,w 但model要讀資料時會要求資料要是四維的array,網路上好像都找不到能把二維轉成四維 的 試過resize但資料好像會跑掉 想請問各位: 有甚麼方法可以把二維array中的array降維變成4D矩陣,或是有甚麼方法讓CNN網絡能夠 讀? 謝謝各位 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.139.67.224 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1589599063.A.E1C.html
littlebo1990: train.reshap(-1,3,3,1) 選我正解05/16 11:54
littlebo1990: 抱歉搞錯了XD 我以為你w,h分別為3, channel是1..05/16 11:55
littlebo1990: 應該是你的np array裡面是object, 所以shape才是05/16 11:57
littlebo1990: 你可以用 list comprehension 把裡面的object變arra05/16 11:59
littlebo1990: i.e train = np.array([i.reshape(w,h,3) for i in05/16 11:59
littlebo1990: train])05/16 12:00
littlebo1990: 這樣train dim就會變(N,w,h,3)05/16 12:00
感謝回覆 但是用list comprehension會回報ValueError: cannot reshape array of siz e 1 into shape (48,140,3) ※ 編輯: grimaceo (223.139.67.224 臺灣), 05/16/2020 12:30:33
eooft: 那個3代表channel數 先弄清楚你的channel是1(黑白)還3(RGB)05/16 13:11
已經解決了 謝謝兩位 ※ 編輯: grimaceo (223.139.67.224 臺灣), 05/16/2020 14:53:11