atlantistin / Blogs

16 stars 16 forks source link

[汉字数据集]TypeError: zip argument #1 must support iteration #6

Open Tylerrrrrrr007 opened 4 years ago

Tylerrrrrrr007 commented 4 years ago
for serial, (ziti, back) in enumerate(zip(gener_ziti(zi, n=10), gener_back())):  # n=5, 生成5张/字体

TypeError: zip argument #1 must support iteration

求问:为什么不可迭代了?原代码没动

数据集

data_directory = "data" with open("all.txt", 'r', encoding="utf-8") as fr: zi_sets = fr.read() for i, zi in enumerate(zi_sets):

目录准备

zi_directory = os.path.join(data_directory, zi)
if not os.path.exists(zi_directory):
    os.makedirs(zi_directory)
# 开始生成
for serial, (ziti, back) in enumerate(zip(gener_ziti(zi, n=10), gener_back())):  # n=5, 生成5张/字体
    img = Image.fromarray(np.array(ziti) // 5 * 3 + np.array(back) // 5 * 2)
    img_path = os.path.join(zi_directory, str(serial) + ".jpg")
    img.save(img_path, "JPEG")
Tylerrrrrrr007 commented 4 years ago

若不使用错切可注释掉

    '''theta = np.random.randint(-15, 15) * np.pi / 180
    M_shear = np.array([[1, np.tan(theta), 0], [0, 1, 0]], dtype=np.float32)'''
    M_shear = np.array([[1, np.tan(0), 0], [0, 1, 0]], dtype=np.float32)
    _img = Image.fromarray(cv2.warpAffine(np.array(_img), M_shear, hanzi_size))
    yield _img

解决了,上边这个东西不能整个注释掉QAQ