关于CNN基本概念知识,建议先阅读以下大神链接的讲解:
借用上面链接中的cnn结构图:
下面用keras框架库获取minst 分类的中间特征图:
预备工作,获取minst数据:
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train = X_train.reshape(X_train.shape[0], 28, 28, 1)
X_test = X_test.reshape(X_test.shape[0], 28, 28, 1)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255
Y_train = np_utils.to_categorical(y_train, 10)
Y_test = np_utils.to_categorical(y_test, 10)
第一步 查看前20张minst原始图, size:(28, 28):
X_Show = X_test.reshape(X_test.shape[0], 28, 28)
X_Show *= 255
print "img shape:{}".format(X_Show[0].shape)
test_img = X_Show[0]
for item in X_Show[1:20]:
test_img = np.append(test_img, item, axis=1)
cv2.imshow("test1", test_img)
第二步 查看经过第一次卷积后的特征图各取前32个特征图, size:(26, 26):
版权声明:本文为cmdholder原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。