pix2pix tensorflow:UnicodeDecodeError:'utf-8'编解码器无法解码位置0的字节0xff:无效的起始字节

时间:2017-04-16 04:39:33

标签: python

此代码位于https://github.com/affinelayer/pix2pix-tensorflow/tree/master/tools;

当我在终端中运行时:

python3 tools/process.py --input_dir mytest --operation resize --output_dir photos/resized,

我遇到了这个问题:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

以下是代码:

def resize(src):
    height, width, _ = src.shape
    dst = src
    if height != width:
        if a.pad:
            size = max(height, width)
            # pad to correct ratio
            oh = (size - height) // 2
            ow = (size - width) // 2
            dst = im.pad(image=dst, offset_height=oh, offset_width=ow, target_height=size, target_width=size)
        else:
            # crop to correct ratio
            size = min(height, width)
            oh = (height - size) // 2
            ow = (width - size) // 2
            dst = im.crop(image=dst, offset_height=oh, offset_width=ow, target_height=size, target_width=size)

    assert(dst.shape[0] == dst.shape[1])

    size, _, _ = dst.shape
    if size > a.size:
        dst = im.downscale(images=dst, size=[a.size, a.size])
    elif size < a.size:
        dst = im.upscale(images=dst, size=[a.size, a.size])
    return dst

1 个答案:

答案 0 :(得分:-1)

明显的原因是有效的UTF-8不能包含值为0xff的字节。我不知道你的代码的哪一部分试图读取UTF-8,但无论它试图读什么,它都不是UTF-8。