summaryrefslogtreecommitdiff
path: root/src/text_recognizer/models/character_model.py
diff options
context:
space:
mode:
authoraktersnurra <gustaf.rydholm@gmail.com>2020-08-20 22:18:35 +0200
committeraktersnurra <gustaf.rydholm@gmail.com>2020-08-20 22:18:35 +0200
commit1f459ba19422593de325983040e176f97cf4ffc0 (patch)
tree89fef442d5dbe0c83253e9566d1762f0704f64e2 /src/text_recognizer/models/character_model.py
parent95cbdf5bc1cc9639febda23c28d8f464c998b214 (diff)
A lot of stuff working :D. ResNet implemented!
Diffstat (limited to 'src/text_recognizer/models/character_model.py')
-rw-r--r--src/text_recognizer/models/character_model.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/text_recognizer/models/character_model.py b/src/text_recognizer/models/character_model.py
index 0a0ab2d..0fd7afd 100644
--- a/src/text_recognizer/models/character_model.py
+++ b/src/text_recognizer/models/character_model.py
@@ -44,6 +44,7 @@ class CharacterModel(Model):
self.tensor_transform = ToTensor()
self.softmax = nn.Softmax(dim=0)
+ @torch.no_grad()
def predict_on_image(
self, image: Union[np.ndarray, torch.Tensor]
) -> Tuple[str, float]:
@@ -64,10 +65,9 @@ class CharacterModel(Model):
# If the image is an unscaled tensor.
image = image.type("torch.FloatTensor") / 255
- with torch.no_grad():
- # Put the image tensor on the device the model weights are on.
- image = image.to(self.device)
- logits = self.network(image)
+ # Put the image tensor on the device the model weights are on.
+ image = image.to(self.device)
+ logits = self.network(image)
prediction = self.softmax(logits.data.squeeze())