-
Notifications
You must be signed in to change notification settings - Fork 131
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
Built In Jupyter Notebook #213
Merged
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6f61e02
WIP: Adding built in notebook for user friendly dev experience
paulguerrie 30a83b2
Merge branch 'main' of https://github.com/roboflow/inference into fea…
paulguerrie ea7ea02
Working jupyter notebook integration with several example notebooks. …
paulguerrie 120f30a
Added args to the `inference server start` command. One is `--roboflo…
paulguerrie f43e759
Added jupyter deps to other dockerfiles
paulguerrie 38b246f
Updated landing page with more copy
paulguerrie 54f0c82
More updates to landing page copy
paulguerrie ff04ca7
s-s-styling!
kresetar a933f32
whoops had an error w some text
kresetar 58baac9
Merge branch 'main' of https://github.com/roboflow/inference into fea…
paulguerrie 69b2157
Enabled GPU for notebook in gpu container. Also added landing page st…
paulguerrie 78f9462
Make style
paulguerrie 67b7159
Small fix for gpu dockerfile building
paulguerrie 209b560
Add api_key arg to inference pipeline notebook example.
paulguerrie 6658654
Removed wheel making from jetson since the bespoke dependencies break…
paulguerrie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "83db9682-cfc4-4cd0-889f-c8747c4033b3", | ||
"metadata": {}, | ||
"source": [ | ||
"# Inference Pipeline\n", | ||
"\n", | ||
"Inference Pipelines are a great way to process video streams with Inference. You can configure different sources that include streams from local devices, RTSP streams, and local video files. You can also configure different sinks that include UDP streaming of results, render of results, and custom callbacks to run your own logic after each new set of predictions is available. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "4ec4136f-53e9-4c8c-9217-a2c533d498ae", | ||
"metadata": {}, | ||
"source": [ | ||
"### Roboflow API Key\n", | ||
"\n", | ||
"To load models with `inference`, you'll need a Roboflow API Key. Find instructions for retrieving your API key [here](https://docs.roboflow.com/api-reference/authentication). The utility function below attempts to load your Roboflow API key from your enviornment. If it isn't found, it then prompts you to input it. To avoid needing to input your API key for each example, you can configure your Roboflow API key in your environment via the variable `ROBOFLOW_API_KEY`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "af3aad40-d41b-4bc1-ade8-dac052951257", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from utils import get_roboflow_api_key\n", | ||
"\n", | ||
"api_key = get_roboflow_api_key()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "86f3f805-f628-4e94-91ac-3b2f44bebdc0", | ||
"metadata": {}, | ||
"source": [ | ||
"### Inference Pipeline Example\n", | ||
"\n", | ||
"In this example we create a new InferencePipeline. We pass the model ID, the video reference, and a method to render our results. Out pipeline does the rest!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "58dd049c-dcc6-4d0b-85ad-e6d1c0ba805b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from functools import partial\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"from matplotlib import pyplot as plt\n", | ||
"from IPython import display\n", | ||
"\n", | ||
"from inference.core.interfaces.stream.inference_pipeline import InferencePipeline\n", | ||
"from inference.core.interfaces.stream.sinks import render_boxes\n", | ||
"\n", | ||
"# Define source video\n", | ||
"video_url = \"https://storage.googleapis.com/com-roboflow-marketing/football-video.mp4\"\n", | ||
"\n", | ||
"# Prepare to plot results\n", | ||
"\n", | ||
"fig, ax = plt.subplots()\n", | ||
"frame_placeholder = np.zeros((480, 640, 3), dtype=np.uint8) # Adjust the dimensions to match your frame size\n", | ||
"image_display = ax.imshow(frame_placeholder)\n", | ||
"\n", | ||
"# Define our plotting function\n", | ||
"def update_plot(new_frame):\n", | ||
" # Update the image displayed\n", | ||
" image_display.set_data(new_frame)\n", | ||
" # Redraw the canvas immediately\n", | ||
" display.display(plt.gcf())\n", | ||
" display.clear_output(wait=True)\n", | ||
"\n", | ||
"# Define our pipeline's sink\n", | ||
"render = partial(render_boxes, on_frame_rendered=update_plot)\n", | ||
"\n", | ||
"# Instantiate the pipeline\n", | ||
"pipeline = InferencePipeline.init(\n", | ||
" model_id=\"soccer-players-5fuqs/1\",\n", | ||
" video_reference=video_url,\n", | ||
" on_prediction=render,\n", | ||
")\n", | ||
"\n", | ||
"# Start the pipeline\n", | ||
"pipeline.start()\n", | ||
"pipeline.join()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "07762936-ff33-46c0-a4a2-0a8e729053d1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.18" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import getpass | ||
import requests | ||
|
||
import cv2 | ||
import numpy as np | ||
|
||
from inference.core.env import API_KEY | ||
|
||
def get_roboflow_api_key(): | ||
if API_KEY is None: | ||
api_key = getpass.getpass("Roboflow API Key:") | ||
else: | ||
api_key = API_KEY | ||
return api_key | ||
|
||
def load_image_from_url(url): | ||
# Send a GET request to the URL | ||
response = requests.get(url) | ||
|
||
# Ensure that the request was successful | ||
if response.status_code == 200: | ||
# Convert the response content into a numpy array | ||
image_array = np.asarray(bytearray(response.content), dtype=np.uint8) | ||
|
||
# Decode the image array into an OpenCV image | ||
image = cv2.imdecode(image_array, cv2.IMREAD_COLOR) | ||
|
||
return image | ||
else: | ||
print(f"Failed to retrieve the image. HTTP status code: {response.status_code}") | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from pydantic import BaseModel, Field, ValidationError | ||
|
||
|
||
class NotebookStartResponse(BaseModel): | ||
"""Response model for notebook start request""" | ||
|
||
success: str = Field(..., description="Status of the request") | ||
message: str = Field(..., description="Message of the request", optional=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably should be post?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how that would work with redirect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, I'm not sure how the redirect works with POST. I'm going to leave it as GET for now since it's working and we don't expect users to be invoking this route other than through our own landing page.