Skip to content

Commit

Permalink
Repair OCR RuntimeError: Expected all tensors to be on the same devic…
Browse files Browse the repository at this point in the history
…e, but found at least two devices, cuda:0 and cpu!
  • Loading branch information
dmitroprobachay committed Jan 6, 2025
1 parent b279baa commit f1ee5d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions nomeroff_net/nnmodels/ocr_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ def calculate_loss(self, logits, texts):
logits_lens = torch.full(size=(batch_size,), fill_value=input_len, dtype=torch.int32)
# calculate ctc
loss = self.criterion(
logits,
encoded_texts,
logits.to(device),
encoded_texts.to(device),
logits_lens.to(device),
text_lens)
text_lens.to(device))
return loss

def step(self, batch):
Expand Down
6 changes: 3 additions & 3 deletions nomeroff_net/pipes/number_plate_text_readers/base/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,10 @@ def get_acc(self, predicted: List, decode: List) -> torch.Tensor:
logits_lens = torch.full(size=(batch_size,), fill_value=input_len, dtype=torch.int32)

acc = functional.ctc_loss(
logits,
encoded_texts,
logits.to(device),
encoded_texts.to(device),
logits_lens.to(device),
text_lens
text_lens.to(device)
)
return 1 - acc / len(self.letters)

Expand Down

0 comments on commit f1ee5d4

Please sign in to comment.