在Tensorflow使用CNN神經網絡進行圖像分類的時候,常常會面對,識別圖像和網絡訓練的維度不同問題,記錄一轉換圖像維度代碼。
IMAGE_HEIGHT = 60
IMAGE_WIDTH = 160
char_set = number
CHAR_SET_LEN = len(char_set)
text2, image2 = gen_captcha_text_and_image()
text="kyb5"
image = cv2.imread("../data/image1.png")
f = plt.figure()
ax = f.add_subplot(111)
ax.text(0.1, 0.9,text, ha='center', va='center', transform=ax.transAxes)
plt.imshow(image)
plt.show()
image=image.transpose(0,1,2)
image=cv2.resize(image,(IMAGE_WIDTH,IMAGE_HEIGHT))
f = plt.figure()
ax = f.add_subplot(111)
ax.text(0.1, 0.9, text, ha='center', va='center', transform=ax.transAxes)
plt.imshow(image)
plt.show()
print(image.shape)
MAX_CAPTCHA = len(text)
print("-------------------------")
print(image2.shape)
print(text2)