-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请问关于pytorch版本该如何修改测试自己的数据集? #43
Comments
class CaptchaDataset(Dataset):
def __init__(self, characters, length, width, height, input_length, label_length):
super(CaptchaDataset, self).__init__()
self.characters = characters
self.length = length
self.width = width
self.height = height
self.input_length = input_length
self.label_length = label_length
self.n_class = len(characters)
self.generator = ImageCaptcha(width=width, height=height)
def __len__(self):
return self.length
def __getitem__(self, index):
random_str = ''.join([random.choice(self.characters[1:]) for j in range(self.label_length)])
image = to_tensor(self.generator.generate_image(random_str))
target = torch.tensor([self.characters.find(x) for x in random_str], dtype=torch.long)
input_length = torch.full(size=(1, ), fill_value=self.input_length, dtype=torch.long)
target_length = torch.full(size=(1, ), fill_value=self.label_length, dtype=torch.long)
return image, target, input_length, target_length 实现一个上面的自定义 Dataset 类, init 改为输入一个文件夹以及必要的信息,然后在 getitem 里读图,只要下面的代码能跑通,你就可以使用此 dataset 去测试。 dataset = CaptchaDataset(characters, 1, width, height, n_input_length, n_len)
image, target, input_length, label_length = dataset[0]
print(''.join([characters[x] for x in target]), input_length, label_length)
to_pil_image(image) |
非常感谢您的回答,这对于我新手来说是开始,
再次感谢您的帮助
江半德
…------------------ 原始邮件 ------------------
发件人: "杨培文 (Yang Peiwen)"<[email protected]>;
发送时间: 2019年11月1日(星期五) 晚上10:35
收件人: "ypwhs/captcha_break"<[email protected]>;
抄送: "江半德"<[email protected]>;"Author"<[email protected]>;
主题: Re: [ypwhs/captcha_break] 请问关于pytorch版本该如何修改测试自己的数据集? (#43)
class CaptchaDataset(Dataset): def __init__(self, characters, length, width, height, input_length, label_length): super(CaptchaDataset, self).__init__() self.characters = characters self.length = length self.width = width self.height = height self.input_length = input_length self.label_length = label_length self.n_class = len(characters) self.generator = ImageCaptcha(width=width, height=height) def __len__(self): return self.length def __getitem__(self, index): random_str = ''.join([random.choice(self.characters[1:]) for j in range(self.label_length)]) image = to_tensor(self.generator.generate_image(random_str)) target = torch.tensor([self.characters.find(x) for x in random_str], dtype=torch.long) input_length = torch.full(size=(1, ), fill_value=self.input_length, dtype=torch.long) target_length = torch.full(size=(1, ), fill_value=self.label_length, dtype=torch.long) return image, target, input_length, target_length
实现一个上面的自定义 Dataset 类, init 改为输入一个文件夹以及必要的信息,然后在 getitem 里读图,只要下面的代码能跑通,你就可以使用此 dataset 去测试。
dataset = CaptchaDataset(characters, 1, width, height, n_input_length, n_len) image, target, input_length, label_length = dataset[0] print(''.join([characters[x] for x in target]), input_length, label_length) to_pil_image(image)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
比如自己测试集在“当前目录的test的文件夹”里面
The text was updated successfully, but these errors were encountered: