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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章