Tensorflow使用CNN 遇到的問題記錄:讀取圖片的維度轉換

在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 = Image.open("../data/image1.png")
        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=np.asarray(image)
        # 轉換維度:
        # print(image.shape)
        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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章