Skip to content

Commit

Permalink
added version node to server and eveluation code
Browse files Browse the repository at this point in the history
  • Loading branch information
JanRiedelsheimer committed Nov 18, 2024
1 parent a37a645 commit 0bafeb3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
7 changes: 7 additions & 0 deletions http_submission/model_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def conditional_log_density():
return jsonify({'log_density': log_density.tolist()})


@app.route('/type', methods=['GET'])
def type():
type = "ScanpathModel"
version = "v1.0.0"
return jsonify({'type': type, 'version': version})


def main():
app.run(host="localhost", port="4000", debug="True", threaded=True)

Expand Down
24 changes: 20 additions & 4 deletions http_submission/sample_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
class HTTPScanpathModel(MySimpleScanpathModel):
def __init__(self, url):
self.url = url
self.log_density_url = url + "/conditional_log_density"
self.type_url = url + "/type"




def conditional_log_density(self, stimulus, x_hist, y_hist, t_hist, attributes=None, out=None):

Expand All @@ -35,27 +40,38 @@ def _convert_attribute(attribute):
}

# send request
response = requests.post(f"{self.url}", data={'json_data': json.dumps(json_data)}, files={'stimulus': image_bytes.getvalue()})
response = requests.post(f"{self.log_density_url}", data={'json_data': json.dumps(json_data)}, files={'stimulus': image_bytes.getvalue()})

# parse response
if response.status_code != 200:
raise ValueError(f"Server returned status code {response.status_code}")

return np.array(response.json()['log_density'])

def type(self):
response = requests.get(f"{self.type_url}")
return np.array(response.json())


if __name__ == "__main__":
http_model = HTTPScanpathModel("http://localhost:4000/conditional_log_density")
http_model = HTTPScanpathModel("http://localhost:4000")

# get MIT1003 dataset
stimuli, fixations = pysaliency.get_mit1003(location='pysaliency_datasets')
fixation_index = 32185

# get server response for one stimulus
server_response = http_model.conditional_log_density(
server_density = http_model.conditional_log_density(
stimulus=stimuli.stimuli[fixations.n[fixation_index]],
x_hist=fixations.x_hist[fixation_index],
y_hist=fixations.y_hist[fixation_index],
t_hist=fixations.t_hist[fixation_index]
)
# get server version
server_version = http_model.type()
print(server_version)


# TODO: delete plotting part
# plot server response, only for testing

Expand All @@ -67,7 +83,7 @@ def _convert_attribute(attribute):
plot_scanpath(stimuli, fixations, fixation_index, visualize_next_saccade=True, ax=axs[0])
axs[0].set_title("Image")

axs[1].imshow(server_response)
axs[1].imshow(server_density)

axs[1].set_title("http_model_log_density")
fig.savefig("test.png")

0 comments on commit 0bafeb3

Please sign in to comment.