深度学习 cnn pytorch框架报错 size mismatch, m1: [ x ], m2: [ x ] Captcha.ImageCaptcha设置生成图片的大小尺寸

看总结直接拉最后

这里很大程度是因为图片大小不一致,可以通过 resize命令来进行图片的归一化.

如果是通过captcha库里面的ImageCaptcha生成的验证码,百度上 没有任何资料说可以改变图片大小作为训练的.但是直接看他的代码得知,他是可以设置图片长宽和大小的

class ImageCaptcha(_Captcha):
    """Create an image CAPTCHA.

    Many of the codes are borrowed from wheezy.captcha, with a modification
    for memory and developer friendly.

    ImageCaptcha has one built-in font, DroidSansMono, which is licensed under
    Apache License 2. You should always use your own fonts::

        captcha = ImageCaptcha(fonts=['/path/to/A.ttf', '/path/to/B.ttf'])

    You can put as many fonts as you like. But be aware of your memory, all of
    the fonts are loaded into your memory, so keep them a lot, but not too
    many.

    :param width: The width of the CAPTCHA image.
    :param height: The height of the CAPTCHA image.
    :param fonts: Fonts to be used to generate CAPTCHA images.
    :param font_sizes: Random choose a font size from this parameters.
    """
    def __init__(self, width=200, height=100, fonts=None, font_sizes=None):
        self._width = width
        self._height = height
        self._fonts = fonts or DEFAULT_FONTS
        self._font_sizes = font_sizes or (42, 50, 56)
        self._truefonts = []

在创建对象的时候给他赋值就可以.

基本出现这个错误就是图片大小不一致,或者传入的图片处理过程中出错的. 把图片输出一下看看图片属性很好排查的

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