Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bag-input #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions mirror/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ def build(self, inputs, model, visualisations=[]):
if len(inputs) <= 0: raise ValueError('At least one input is required.')

self.inputs, self.model = inputs, model

self.current_input = self.inputs[0].unsqueeze(0).to(self.device) # add 1 dim for batch

#Iterate bag of inputs
for i in range(len(self.inputs)):
# Add mini-batch dim if not exist
if len(self.inputs[i].size()) == 1:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I am wrong, if the inputs is a tensor with shape >2 then it won't have the batch dim in the first. So you want to be able to pass multiple inputs to your model at once, am I right?

Copy link
Author

@rs9000 rs9000 Jan 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to pass as input an array which contains tensors that already have the mini batch size.

Many models require two inputs, vqa for example, require image and question.
They are usually packed into an array where input[0] is the image and input[1] is the question.

My fix want iterate over the input array and for each tensor we add mini-batch only if the shape is equal to 1. Because tensors with shape > 1 I suppose already have a mini-batch size.

self.inputs[i] = self.inputs[i].unsqueeze(0).to(self.device)

self.current_input = self.inputs
model = model.to(self.device)
model.eval()
# instantiate a Tracer object to create a graph from the model
Expand Down Expand Up @@ -172,4 +178,4 @@ def api_model_layer_output_image(input_id, vis_id, layer_id, time, output_id):
except KeyError:
return Response(status=500, response='Index not found.')

return app
return app