forked from ZiYang-xie/PyCAPTCHA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictor.py
More file actions
32 lines (23 loc) · 784 Bytes
/
predictor.py
File metadata and controls
32 lines (23 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from model.model import captcha_model, model_conv, model_resnet
from utils.arg_parsers import predict_arg_parser
from data.dataset import str_to_vec, lst_to_str
import torchvision.transforms as transforms
from PIL import Image
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
def predict(args):
model = captcha_model.load_from_checkpoint(args.ckpt, model=model_resnet())
model.eval()
img = transform(Image.open(args.input))
img = img.unsqueeze(0)
y = model(img)
y = y.permute(1, 0, 2)
pred = y.argmax(dim=2)
ans = lst_to_str(pred)
print(ans)
return ans
if __name__ == "__main__":
args = predict_arg_parser()
predict(args)