Skip to content

Commit 8c6415b

Browse files
Merge pull request #130 from roboflow/readme-refresh
Readme refresh
2 parents de4090f + 382a463 commit 8c6415b

File tree

2 files changed

+150
-112
lines changed

2 files changed

+150
-112
lines changed

README.md

Lines changed: 96 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,67 @@
1-
# Roboflow Python Library
1+
# Roboflow Python
22

33
---
4-
![roboflow logo](https://i.imgur.com/lXCoVt5.png)
5-
6-
[Website](https://docs.roboflow.com/python)[Docs](https://docs.roboflow.com/python)[Blog](https://blog.roboflow.com)
7-
[Twitter](https://twitter.com/roboflow)[Linkedin](https://www.linkedin.com/company/roboflow-ai)
8-
[Universe](https://universe.roboflow.com)
9-
10-
**Roboflow** makes managing, preprocessing, augmenting, and versioning datasets for computer vision seamless. This is
11-
the official Roboflow python package that interfaces with the [Roboflow API](https://docs.roboflow.com). Key features of
12-
Roboflow:
13-
14-
- Import and Export image datasets into any supported [format](https://roboflow.com/formats)
15-
- [Preprocess](https://docs.roboflow.com/image-transformations/image-preprocessing)
16-
and [augment](https://docs.roboflow.com/image-transformations/image-augmentation) data using Roboflow's dataset
17-
management tools
18-
- Train computer vision models using [Roboflow Train](https://docs.roboflow.com/train) and deploy
19-
to [production](https://docs.roboflow.com/inference)
20-
- Use [community curated projects](https://universe.roboflow.com/) to start building your own vision-powered products
4+
![roboflow logo](https://media.roboflow.com/homepage/cv_pipeline_compact.png?updatedAt=1679939317160)
5+
6+
7+
<div align="center">
8+
<a href="https://youtube.com/roboflow">
9+
<img
10+
src="https://media.roboflow.com/notebooks/template/icons/purple/youtube.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949634652"
11+
width="3%"
12+
/>
13+
</a>
14+
<img src="https://raw.githubusercontent.com/ultralytics/assets/main/social/logo-transparent.png" width="3%"/>
15+
<a href="https://roboflow.com">
16+
<img
17+
src="https://media.roboflow.com/notebooks/template/icons/purple/roboflow-app.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949746649"
18+
width="3%"
19+
/>
20+
</a>
21+
<img src="https://raw.githubusercontent.com/ultralytics/assets/main/social/logo-transparent.png" width="3%"/>
22+
<a href="https://www.linkedin.com/company/roboflow-ai/">
23+
<img
24+
src="https://media.roboflow.com/notebooks/template/icons/purple/linkedin.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949633691"
25+
width="3%"
26+
/>
27+
</a>
28+
<img src="https://raw.githubusercontent.com/ultralytics/assets/main/social/logo-transparent.png" width="3%"/>
29+
<a href="https://docs.roboflow.com">
30+
<img
31+
src="https://media.roboflow.com/notebooks/template/icons/purple/knowledge.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949634511"
32+
width="3%"
33+
/>
34+
</a>
35+
<img src="https://raw.githubusercontent.com/ultralytics/assets/main/social/logo-transparent.png" width="3%"/>
36+
<a href="https://disuss.roboflow.com">
37+
<img
38+
src="https://media.roboflow.com/notebooks/template/icons/purple/forum.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949633584"
39+
width="3%"
40+
/>
41+
<img src="https://raw.githubusercontent.com/ultralytics/assets/main/social/logo-transparent.png" width="3%"/>
42+
<a href="https://blog.roboflow.com">
43+
<img
44+
src="https://media.roboflow.com/notebooks/template/icons/purple/blog.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949633605"
45+
width="3%"
46+
/>
47+
</a>
48+
</a>
49+
</div>
50+
51+
<br>
52+
53+
**Roboflow** streamlines your computer vision pipeline - upload data, label it, download datasets, train models, deploy models, and repeat.
54+
55+
The **Roboflow Python Package** is a python wrapper around the core Roboflow web application and REST API.
56+
57+
We also maintain an open source set of CV utililities and notebook tutorials in Python:
58+
59+
* :fire: https://github.com/roboflow/supervision :fire:
60+
* :fire: https://github.com/roboflow/notebooks :fire:
2161

2262
## Installation
2363

24-
To install this package, please use `Python 3.6` or higher. We provide three different ways to install the Roboflow
25-
package to use within your own projects.
64+
To install this package, please use `Python 3.6` or higher.
2665

2766
Install from PyPi (Recommended):
2867

@@ -40,124 +79,73 @@ source env/bin/activate
4079
pip3 install -r requirements.txt
4180
```
4281

43-
## Quickstart
82+
## Authentication
4483

4584
```python
4685
import roboflow
47-
48-
# Instantiate Roboflow object with your API key
49-
rf = roboflow.Roboflow(api_key=YOUR_API_KEY_HERE)
50-
51-
# List all projects for your workspace
52-
workspace = rf.workspace()
53-
54-
# Load a certain project (workspace url is optional)
55-
project = rf.project("PROJECT_ID")
56-
57-
# List all versions of a specific project
58-
project.versions()
59-
60-
# Upload image to dataset
61-
project.upload("UPLOAD_IMAGE.jpg")
62-
63-
# Retrieve the model of a specific project
64-
model = project.version("1").model
65-
66-
# predict on a local image
67-
prediction = model.predict("YOUR_IMAGE.jpg")
68-
69-
# Predict on a hosted image
70-
prediction = model.predict("YOUR_IMAGE.jpg", hosted=True)
71-
72-
# Plot the prediction
73-
prediction.plot()
74-
75-
# Convert predictions to JSON
76-
prediction.json()
77-
78-
# Save the prediction as an image
79-
prediction.save(output_path='predictions.jpg')
86+
roboflow.login()
8087
```
8188

82-
## Using this package for a specific project
83-
84-
If you have a specific project from your workspace you'd like to run in a notebook, follow along with this tutorial: [Downloading Datasets from Roboflow for Training (Python)](https://www.youtube.com/watch?v=76E6esnez8E).
85-
86-
Selecting the format you'd like your project to be exported as while choosing the `show download code` option will display code snippets you can use in either Jupyter or your terminal. These code snippets will include your `api_key`, project, and workspace names.
87-
88-
![Alt Text](https://media.giphy.com/media/I5g06mUnVzdX7iT2Gf/giphy.gif)
89-
90-
## Developing locally
89+
## Quickstart
9190

92-
### Using Docker
91+
### Datasets
9392

94-
To set the Docker container up for the first time:
93+
Download any of over 200,000 public computer vision datasets from [Roboflow Universe](universe.roboflow.com). Label and download your own datasets on app.roboflow.com.
9594

96-
```bash
97-
# Clone this repo
98-
git clone [email protected]:roboflow-ai/roboflow-python.git && cd roboflow-python
95+
```python
96+
import roboflow
97+
dataset = roboflow.download_dataset(dataset_url="universe.roboflow.com/...", model_format="yolov8")
98+
#ex. dataset = roboflow.download_dataset(dataset_url="https://universe.roboflow.com/joseph-nelson/bccd/dataset/1", model_format="yolov8")
99+
print(dataset.location)
100+
```
99101

100-
# Copy the environment variables template
101-
# Be sure to update the values with your account's information
102+
### Models
102103

103-
# Build our development image
104-
docker build -t roboflow-python -f Dockerfile.dev .
104+
Predict with any of over 50,000 public computer vision models. Train your own computer vision models on app.roboflow.com or train upload your model from open source models - see https://github.com/roboflow/notebooks
105105

106-
# Run container and map current folder in it
107-
docker run --rm -it \
108-
-v $(pwd)/:/workspace/ \
109-
--env-file .env \
110-
roboflow-python
106+
```python
107+
img_url = "https://media.roboflow.com/quickstart/aerial_drone.jpeg?updatedAt=1678743716455"
108+
universe_model_url = "https://universe.roboflow.com/brad-dwyer/aerial-solar-panels/model/6"
111109

112-
# Run tests
113-
python -m unittest
110+
model = roboflow.load_model(model_url=universe_model_url)
111+
pred = model.predict(img_url, hosted=True)
112+
pred.plot()
114113
```
115114

116-
#### Change Python version
117-
118-
You can pass the build arg `PYTHON_VERSION` to dynamically change python version at build time
115+
## Library Structure
119116

120-
```bash
121-
docker build -t roboflow-python --build-arg PYTHON_VERSION=3.9 -f Dockerfile.dev .
122-
```
117+
The Roboflow python library is structured by the core Roboflow application objects.
123118

124-
Will use `python:3.9-slim`
119+
Workspace (workspace.py) --> Project (project.py) --> Version (version.py)
125120

126-
**Note** If you are using [VSCode](https://code.visualstudio.com/) we recommend you read the ["Developing inside a Container"](https://code.visualstudio.com/docs/remote/containers) tutorial.
121+
```python
122+
from roboflow import Roboflow
123+
rf = Roboflow()
124+
workspace = rf.workspace("WORKSPACE_URL")
125+
project = workspace.project("PROJECT_URL")
126+
version = project.version("VERSION_NUMBER")
127+
```
127128

128-
### Using Virtualenv
129+
The workspace, project, and version parameters are the same that you will find in the URL addresses at app.roboflow.com and universe.roboflow.com.
129130

130-
```bash
131-
# Clone this repo
132-
git clone [email protected]:roboflow-ai/roboflow-python.git && cd roboflow-python
131+
Within the workspace object you can perform actions like making a new project, listing your projects, or performing active learning where you are using predictions from one project's model to upload images to a new project.
133132

134-
# create virtual env
135-
virtualenv local_dev
133+
Within the project object, you can retrieve metadata about the project, list versions, generate a new dataset version with preprocessing and augmentation settings, train a model in your project, and upload images and annotations to your project.
136134

137-
# activate virtual env
138-
source local_dev/bin/activate
135+
Within the version object, you can download the dataset version in any model format, train the version on Roboflow, and deploy your own external model to Roboflow.
139136

140-
# install dependencies
141-
pip3 install -e ".[dev]"
142-
```
137+
## Contributing
143138

144-
### Testing
139+
If you want to extend our Python library or if you find a bug, please open a PR!
145140

146-
Make sure you have your `virtualenv` spun up before running tests. Execute the `unittest` command at the `/root` level directory.
141+
Also be sure to test your code the `unittest` command at the `/root` level directory.
147142

148143
Run tests:
149144

150145
```bash
151146
python -m unittest
152147
```
153148

154-
### Contributing
155-
156-
1. Increment the pip package minor version number in `setup.py`
157-
1. Manually add any new dependencies to `requirements.txt` with a version such as `chardet==4.0.0` and list of dependencies in `setup.py` (Be careful not to overwrite any packages that might screw up backwards dependencies for object detection, etc.)
158-
159-
### Code Quality
160-
161149
When creating new functions, please follow the [Google style Python docstrings](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html). See example below:
162150

163151
```python
@@ -184,4 +172,4 @@ make style
184172
make check_code_quality
185173
```
186174

187-
**Note** These tests will be run automatically when you commit thanks to git hooks.
175+
**Note** These tests will be run automatically when you commit thanks to git hooks.

roboflow/__init__.py

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import time
5+
from getpass import getpass
56
from urllib.parse import urlparse
67

78
import requests
@@ -11,7 +12,7 @@
1112
from roboflow.core.workspace import Workspace
1213
from roboflow.util.general import write_line
1314

14-
__version__ = "1.0.1"
15+
__version__ = "1.0.2"
1516

1617

1718
def check_key(api_key, model, notebook, num_retries=0):
@@ -99,7 +100,7 @@ def login(workspace=None, force=False):
99100
+ " to get your authentication token."
100101
)
101102

102-
token = input("Paste the authentication here token here: ")
103+
token = getpass("Paste the authentication token here: ")
103104

104105
r_login = requests.get(APP_URL + "/query/cliAuthToken/" + token)
105106

@@ -132,7 +133,16 @@ def login(workspace=None, force=False):
132133
active_workspace = None
133134

134135

135-
def initialize_roboflow():
136+
def initialize_roboflow(the_workspace=None):
137+
"""High level function to initialize Roboflow.
138+
139+
Args:
140+
the_workspace: the workspace url to initialize. If None, the default workspace will be used.
141+
142+
Returns:
143+
None
144+
"""
145+
136146
global active_workspace
137147

138148
conf_location = os.getenv(
@@ -145,13 +155,24 @@ def initialize_roboflow():
145155
"To use this method, you must first login - run roboflow.login()"
146156
)
147157
else:
148-
if active_workspace == None:
158+
if the_workspace == None:
149159
active_workspace = Roboflow().workspace()
160+
else:
161+
active_workspace = Roboflow().workspace(the_workspace)
150162

151163
return active_workspace
152164

153165

154166
def load_model(model_url):
167+
"""High level function to load Roboflow models.
168+
169+
Args:
170+
model_url: the model url to load. Must be from either app.roboflow.com or universe.roboflow.com
171+
172+
Returns:
173+
the model object to use for inference
174+
"""
175+
155176
operate_workspace = initialize_roboflow()
156177

157178
if "universe.roboflow.com" in model_url or "app.roboflow.com" in model_url:
@@ -170,6 +191,35 @@ def load_model(model_url):
170191
return model
171192

172193

194+
def download_dataset(dataset_url, model_format, location=None):
195+
"""High level function to download data from Roboflow.
196+
197+
Args:
198+
dataset_url: the dataset url to download. Must be from either app.roboflow.com or universe.roboflow.com
199+
model_format: the format the dataset will be downloaded in
200+
location: the location the dataset will be downloaded to
201+
202+
Returns:
203+
The dataset object with location available as dataset.location
204+
"""
205+
206+
if "universe.roboflow.com" in dataset_url or "app.roboflow.com" in dataset_url:
207+
parsed_url = urlparse(dataset_url)
208+
path_parts = parsed_url.path.split("/")
209+
project = path_parts[2]
210+
version = int(path_parts[-1])
211+
the_workspace = path_parts[1]
212+
else:
213+
raise (
214+
"Model URL must be from either app.roboflow.com or universe.roboflow.com"
215+
)
216+
operate_workspace = initialize_roboflow(the_workspace=the_workspace)
217+
218+
project = operate_workspace.project(project)
219+
version = project.version(version)
220+
return version.download(model_format, location)
221+
222+
173223
# continue distributing this object for back compatibility
174224
class Roboflow:
175225
def __init__(

0 commit comments

Comments
 (0)