Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
fix: fix post process
Browse files Browse the repository at this point in the history
  • Loading branch information
heiruwu committed Nov 27, 2023
1 parent e6dbacd commit 69462c3
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions mobilenetv2/1/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ def _image_labels(self) -> List[str]:
categories.append(label.strip())
return categories

def process_model_outputs(self, output: np.array):
probabilities = torch.nn.functional.softmax(torch.from_numpy(output), dim=0)
prob, catid = torch.topk(probabilities, 1)

return catid, prob

def ModelMetadata(self, req: ModelMetadataRequest) -> ModelMetadataResponse:
resp = ModelMetadataResponse(
name=req.name,
Expand Down Expand Up @@ -103,7 +97,7 @@ async def ModelInfer(self, request: ModelInferRequest) -> ModelInferResponse:
# shape=(1, batch_size, 1000)

# tensor([[207], [294]]), tensor([[0.7107], [0.7309]])
cat, score = self.process_model_outputs(out[0])
score, cat = torch.topk(torch.from_numpy(out[0]), 1)
s_out = [
bytes(f"{score[i][0]}:{self.categories[cat[i]]}", "utf-8")
for i in range(cat.size(0))
Expand Down

0 comments on commit 69462c3

Please sign in to comment.