虚空之眼

  • 关注
  • 短消息
  • 送银子
文章
0
评论
4
推荐
0
收藏
0
社区会龄
3 年
个人网站
--
个人简介
还没有输入个人简介……

评论了

  • 今年 02-11 15:28

    会报错吗?我运行的时候没有报错。你试试我的脚本(注意改下相关路径和图片) from keras.applications.vgg16 import VGG16 from keras import backend as K model = VGG16(weights='imagenet') from keras.preprocessing import image from keras.applications.vgg16 import preprocess_input, decode_predictions import numpy as np img_path = 'E:\\test_data\\dog_cat\\test\\cats\\cat.1502.jpg' img = image.load_img(img_path, target_size=(224,224)) x=image.img_to_array(img) x=np.expand_dims(x, axis=0) x=preprocess_input(x) preds = model.predict(x) print('Predicted:', decode_predictions(preds, top=10)[0]) print(np.argmax(preds[0])) cat_output = model.output[:, 285] last_conv_layer = model.get_layer('block5_conv3') grads = K.gradients(cat_output, last_conv_layer.output)[0] pooled_grads = K.mean(grads, axis=(0, 1, 2)) iterate = K.function([model.input], [pooled_grads, last_conv_layer.output[0]]) pooled_grads_value, conv_layer_output_value = iterate([x]) for i in range(512): conv_layer_output_value[:,:,i] *= pooled_grads_value[i] heatmap = np.mean(conv_layer_output_value, axis=-1) import matplotlib.pyplot as plt heatmap = np.maximum(heatmap, 0) heatmap /= np.max(heatmap) plt.matshow(heatmap) plt.show() import cv2 img = cv2.imread(img_path) heatmap = cv2.resize(heatmap, (img.shape[1], img.shape[0])) heatmap = np.uint8(255*heatmap) heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET) superimposed_img = heatmap * 0.4 + img cv2.imwrite('E:\\Anaconda3\\deeplearn\\test\\cat1513_cam.jpg', superimposed_img)

  • 今年 01-02 20:15

    f = open(os.path.join(glove_dir, 'glove.6B.100d.txt'),encoding='gbk',errors='ignore'),加上encoding和error就不报错了。

  • 今年 01-02 14:25

    代码6.6,注意from keras.layers import preprocessing会报错,应为from keras import preprocessing

  • 2018-12-13 16:04

    请用anaconda安装tensorflow以及kearas,之后运行如果keras报错,则import tensorflow之后再import keras

  • 2018-12-13 16:02

    5-39,如果大家跑出来的结果是一堆白格,注意results里面的值是浮点数,而imshow显示的时候如果RGB值为浮点,是需要将results除以256使之在0-1之间的。 VS code会有一条提示“clipping input data to te valid range for imshow with RBG data([0..1] for floats or [0..255] for integers”