歡迎您光臨本站 註冊首頁

淺談cv2.imread()和keras.preprocessing中的image.load

←手機掃碼閱讀     ml5rwbikls @ 2020-06-13 , reply:0

1、image.load_img()

  from keras.preprocessing import image    img_keras = image.load_img('./original/dog/880.jpg')  print(img_keras)    img_keras = image.img_to_array(img_keras)  print(img_keras[:,1,1])

 

效果如下:

  #image.load_img()只是加載了一個文件,沒有形成numpy數組,  #下面的numpy數組是通過image.img_to_array()的函數形成的    [108. 108. 110. 115. 119. 120. 122. 125. 127. 127. 129. 131. 132. 134.   1. 135. 138. 138. 139. 143. 141. 136. 132. 131. 135. 121. 103. 97.   2. 85. 69. 65. 69. 67. 74. 80. 77. 82. 92. 99. 105. 113.   3. 126. 128. 129. 132. 134. 135. 135. 135. 135. 134. 133. 131. 130.   4. 124. 122. 120. 119. 119. 121. 122. 123. 121. 120. 120. 122. 124.   5. 124. 123. 121. 120. 119. 119. 118. 116. 114. 121. 120. 117. 115.   6. 112. 111. 111. 114. 105. 104. 107. 104. 103. 106. 105. 101. 71.   7. 99. 99. 77. 71. 80. 69. 71. 69. 65. 63. 65. 64. 61.   8. 67. 74. 77. 79. 81. 79. 76. 78. 78. 77. 75. 77. 79.   9. 72. 68. 68. 67. 66. 64. 63. 61. 61. 57. 57. 56. 56.   10. 51. 45. 42. 34. 31. 28. 26. 27. 28. 28. 28. 29. 29.   11. 28. 27. 26. 25. 26. 24. 23. 22. 21. 21. 21. 22. 22.   12. 21. 21. 20. 20. 20. 19. 19. 19. 18. 18. 18. 18. 18.   13. 18. 18. 18. 17. 16. 14. 13. 12. 12. 10. 10. 10. 10.   14.  9.  9.  8. 10. 10. 10. 10. 12. 15. 18. 20. 23. 20.   15. 175. 229. 231. 230. 221. 219. 220. 227. 223. 213. 220. 227. 221.   16. 216. 219. 214. 197. 187. 179. 165. 175. 160. 175. 201. 206. 207.   17. 196. 178. 189. 207. 195. 190. 188. 152. 124. 97. 113. 179. 214.   18. 122. 172. 178. 204. 196. 200. 184. 167. 147. 112. 106. 131. 193.   19. 202. 188. 187. 199. 206. 207. 208. 172. 139. 147. 128. 130. 215.   20. 224. 221. 219. 217. 218. 206. 185. 158. 180. 174. 173. 142. 139.   21. 200. 202. 205. 174. 122. 119. 123. 120. 155. 206. 160. 191. 191.   22. 182. 158. 116. 66. 29.  6. 22. 47. 54. 53. 55. 61. 64.   23. 75. 80. 84. 86. 88. 87. 88. 89. 89. 88. 87. 86. 86.   24. 71. 174. 136. 13.  7. 38. 68. 77. 79. 80. 81. 81. 80.   25. 78. 77. 77. 77. 77. 76. 76. 76. 75. 74. 75. 75. 75.   26. 73. 71. 70. 68. 65. 62. 59. 57. 55. 52. 49. 46. 43.   27. 34. 31. 28. 25. 23.]

 

2、cv2.imread()

  import cv2    img_cv2 = cv2.imread('./original/dog/880.jpg')  print(img_cv2[:,1,1])

 

效果如下:

  [108 108 110 115 119 120 122 125 127 127 129 131 132 134 134 135 138 138   139 143 141 136 132 131 135 121 103 97 97 85 69 65 69 67 74 80   77 82 92 99 105 113 120 126 128 129 132 134 135 135 135 135 134 133   131 130 126 124 122 120 119 119 121 122 123 121 120 120 122 124 124 124   123 121 120 119 119 118 116 114 121 120 117 115 113 112 111 111 114 105   104 107 104 103 106 105 101 71 72 99 99 77 71 80 69 71 69 65   63 65 64 61 62 67 74 77 79 81 79 76 78 78 77 75 77 79   76 72 68 68 67 66 64 63 61 61 57 57 56 56 54 51 45 42   34 31 28 26 27 28 28 28 29 29 28 28 27 26 25 26 24 23   22 21 21 21 22 22 21 21 21 20 20 20 19 19 19 18 18 18   18 18 18 18 18 18 17 16 14 13 12 12 10 10 10 10  9  9    9  8 10 10 10 10 12 15 18 20 23 20 27 175 229 231 230 221   219 220 227 223 213 220 227 221 220 216 219 214 197 187 179 165 175 160   175 201 206 207 207 196 178 189 207 195 190 188 152 124 97 113 179 214   147 122 172 178 204 196 200 184 167 147 112 106 131 193 218 202 188 187   199 206 207 208 172 139 147 128 130 215 228 224 221 219 217 218 206 185   158 180 174 173 142 139 151 200 202 205 174 122 119 123 120 155 206 160   191 191 192 182 158 116 66 29  6 22 47 54 53 55 61 64 69 75   80 84 86 88 87 88 89 89 88 87 86 86 92 71 174 136 13  7   38 68 77 79 80 81 81 80 79 78 77 77 77 77 76 76 76 75   74 75 75 75 74 73 71 70 68 65 62 59 57 55 52 49 46 43   38 34 31 28 25 23]

 

補充知識:keras報錯:load_weights() got an unexpected keyword arguement 'skip_mmismatch'

網上下載了一個Yolo(keras+tensorflow)網絡的訓練代碼,在運行的時候,報了以下錯誤:

load_weights() got an unexpected keyword arguement 'skip_mmismatch'。

在網上搜索了半天,也沒有發現具體原因,最後,仔細看了看這句話的報錯,因為我調用的是一個keras的內置函數,卻報了沒有這個參數的錯,就想到了版本問題。最後將keras進行升級(我的升級到了2.1.5版本),這個問題就解決了。

總結:

在跑keras和tensorflow程序的時候遇到了好多次這種版本導致的問題。因為深度學習現在發展比較迅速,所以很多框架的API更新比較快,以後debug的時候一定要注意排查版本問題。


[ml5rwbikls ] 淺談cv2.imread()和keras.preprocessing中的image.load已經有269次圍觀

http://coctec.com/docs/python/shhow-post-238385.html