Skip to content

Commit

Permalink
Fix yolact
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoin committed Jul 11, 2023
1 parent 285dc8f commit 1b8efc5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/deepsparse/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
from deepsparse.utils import (
generate_random_inputs,
get_output_names,
join_engine_outputs,
model_to_path,
override_onnx_input_shapes,
split_engine_inputs,
join_engine_outputs,
)


Expand Down
2 changes: 0 additions & 2 deletions src/deepsparse/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ def split_engine_inputs(
[arr[section_idx : section_idx + batch_size] for arr in items]
)

print(f"sliced up {total_batch_size} into {len(batches)} pieces")

return batches, total_batch_size


Expand Down
27 changes: 9 additions & 18 deletions src/deepsparse/yolact/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,6 @@ def process_inputs(
)
return [image_batch], postprocessing_kwargs

@staticmethod
def join_engine_outputs(
batch_outputs: List[List[numpy.ndarray]],
) -> List[numpy.ndarray]:
boxes, confidence, masks, priors, protos = Pipeline.join_engine_outputs(
batch_outputs
)

# priors never has a batch dimension
# so the above step doesn't concat along a batch dimension
# reshape into a batch dimension
num_priors = boxes.shape[1]
batch_priors = numpy.reshape(priors, (-1, num_priors, 4))

# all the priors should be equal, so only use the first one
assert (batch_priors == batch_priors[0]).all()
return [boxes, confidence, masks, batch_priors[0], protos]

def _preprocess_image(self, image) -> numpy.ndarray:
if isinstance(image, str):
image = cv2.imread(image)
Expand All @@ -209,6 +191,15 @@ def process_engine_outputs(
priors = torch.from_numpy(priors).cpu()
protos = torch.from_numpy(protos).cpu()

# priors never has a batch dimension
# so the above step doesn't concat along a batch dimension
# reshape into a batch dimension
# all the priors should be equal, so only use the first one
num_priors = boxes.shape[1]
batch_priors = numpy.reshape(priors, (-1, num_priors, 4))
assert (batch_priors == batch_priors[0]).all()
priors = batch_priors[0]

batch_size, num_priors, _ = boxes.size()

# Preprocess every image in the batch individually
Expand Down

0 comments on commit 1b8efc5

Please sign in to comment.