TShopping

 找回密碼
 註冊
搜索
查看: 882|回復: 0

[教學] python VGG16影像轉CSV

[複製鏈接]
發表於 2021-3-11 22:56:35 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
原圖:

python VGG16 影像轉CSV

python VGG16 影像轉CSV



結果圖:

python VGG16 影像轉CSV

python VGG16 影像轉CSV



完整代碼:
  1. from keras.applications.vgg16 import VGG16
  2. from keras.applications.vgg16 import preprocess_input
  3. from keras.preprocessing.image import load_img
  4. from keras.preprocessing.image import img_to_array
  5. from keras.models import Model
  6. from matplotlib import pyplot as plt
  7. from numpy import expand_dims
  8. model = VGG16()
  9. model = Model(inputs=model.inputs, outputs=model.layers[2].output)
  10. #summary 預設
  11. model.summary()
  12. # VGG16 只能用target_size=(224,224)
  13. img = load_img('luffy.jpg',target_size=(224,224))
  14. img = img_to_array(img)
  15. print(img)
  16. print(img.shape)
  17. img = expand_dims(img, axis=0)
  18. print(img)
  19. print(img.shape)
  20. img = preprocess_input(img)
  21. feature_maps = model.predict(img)
  22. square = 8
  23. ix = 1
  24. for _ in range(square):
  25.     for _ in range(square):
  26.         ax = plt.subplot(square,square,ix)
  27.         ax.set_xticks([])
  28.         ax.set_yticks([])
  29.         plt.imshow(feature_maps[0, :, :, ix - 1], cmap='gray')
  30.         ix += 1
  31. plt.show()
複製代碼



 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-3-29 13:00 , Processed in 0.052316 second(s), 26 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表