-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
test.py | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1 @@ | ||
# Roboflow Python Library | ||
|
||
This is a helper library to load your [Roboflow](https://roboflow.ai) datasets | ||
into your python scripts and Jupyter notebooks. | ||
|
||
## Requirements | ||
|
||
This package requires python >=3.6 and a (free) | ||
[Roboflow](https://roboflow.ai) account. | ||
|
||
## Installing | ||
|
||
#### With PIP | ||
```sh | ||
pip install roboflow | ||
``` | ||
|
||
#### With Anaconda | ||
```sh | ||
conda install roboflow | ||
``` | ||
|
||
## Setup | ||
|
||
The `roboflow` package works in conjunction with your | ||
[Roboflow](https://roboflow.ai) account. | ||
|
||
From your `Account` page, click `Roboflow Keys` to get your API key. | ||
You can then use the `roboflow` python package to manage downloading | ||
your datasets in various formats. | ||
|
||
```python | ||
import roboflow | ||
roboflow.auth("<<YOUR API KEY>>") | ||
info = roboflow.load("chess-sample", 1, "tfrecord") | ||
|
||
# dataset is now downloaded and unzipped in your current directory | ||
# and info contains the paths you need to load it into your favorite | ||
# machine learning libraries | ||
``` | ||
|
||
By default the folder is named | ||
``` | ||
${dataset-name}.${version-number}-${version-name}.${format} | ||
``` | ||
(For example, `Chess Sample.v1-small-gray.coco`). | ||
|
||
The file hierarchy is three folders containing the `train`, `valid`, and `test` | ||
data you selected in the Roboflow upload flow (and the format you specified | ||
in `roboflow.load` above). There is also a `README.roboflow.txt` describing the preprocessing and augmentation steps and, optionally, a `README.dataset.txt` | ||
provided by the person who shared the dataset. | ||
|
||
 | ||
|
||
## Doing Inference | ||
It's important to pre-process your images for inference the same way you | ||
pre-processed your training images. For this, get a pre-processor via the | ||
`roboflow.infer` method which will return a function you can use to pre-process | ||
your images. | ||
|
||
```python | ||
import roboflow | ||
roboflow.auth("<<YOUR API KEY>>") | ||
process = roboflow.preprocessor("chess-sample", 1) | ||
images = process.fromFile("example.jpg") # returns a numpy array (of 1 image, unless you used tiling) | ||
``` | ||
|
||
## Benefits | ||
|
||
This package currently provides two main benefits over downloading and loading | ||
your datasets manually. | ||
|
||
1. If you have previously loaded your dataset, it will automatically use the local copy rather than re-downloading. | ||
2. You can dynamically choose the export format at runtime rather than export-time. | ||
|
||
## Roadmap | ||
|
||
We plan to include more features in the future to allow you (for example, | ||
to let you easily do inference on your trained models). | ||
# Roboflow Python Library |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[build-system] | ||
requires = [ | ||
"setuptools>=57", | ||
"wheel" | ||
] | ||
build-backend = "setuptools.build_meta" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
certifi==2021.5.30 | ||
chardet==4.0.0 | ||
cycler==0.10.0 | ||
idna==2.10 | ||
kiwisolver==1.3.1 | ||
matplotlib==3.4.2 | ||
numpy==1.21.0 | ||
opencv-python==4.5.3.56 | ||
Pillow==8.3.0 | ||
pyparsing==2.4.7 | ||
python-dateutil==2.8.1 | ||
python-dotenv==0.18.0 | ||
requests==2.25.1 | ||
six==1.16.0 | ||
urllib3==1.26.6 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,53 @@ | ||
import json | ||
import time | ||
|
||
import requests | ||
|
||
API_URL = "https://api.roboflow.ai" | ||
_token = None | ||
_token_expires = 0 | ||
from roboflow.core.project import Project | ||
|
||
def token(): | ||
global _token | ||
return _token | ||
TOKEN = None | ||
API_URL = "http://localhost:5000" | ||
TOKEN_EXPIRES = None | ||
USER_API_KEY = "" | ||
|
||
def auth(api_key): | ||
global _token | ||
|
||
def auth(api_key): | ||
global TOKEN, TOKEN_EXPIRES | ||
global USER_API_KEY | ||
USER_API_KEY = api_key | ||
response = requests.post(API_URL + "/token", data=({ | ||
"api_key": api_key | ||
})) | ||
|
||
r = response.json(); | ||
if "error" in r: | ||
raise RuntimeError(response.text) | ||
|
||
_token = r["token"] | ||
_token_expires = time.time() + r["expires_in"] | ||
|
||
return r | ||
|
||
def dataset(name): | ||
global _token | ||
|
||
if not _token: | ||
raise Exception("You must first auth with your API key to call this method.") | ||
|
||
response = requests.get(API_URL + "/dataset/" + name, params=({ | ||
"access_token": _token | ||
})) | ||
|
||
r = response.json(); | ||
if "error" in r: | ||
raise RuntimeError(response.text) | ||
|
||
return r | ||
|
||
def version(dataset_name, version_id): | ||
global _token | ||
|
||
if not _token: | ||
raise Exception("You must first auth with your API key to call this method.") | ||
|
||
response = requests.get(API_URL + "/dataset/" + dataset_name + '/' + str(version_id), params=({ | ||
"access_token": _token | ||
})) | ||
|
||
r = response.json(); | ||
if "error" in r: | ||
r = response.json() | ||
if "error" in r or response.status_code != 200: | ||
raise RuntimeError(response.text) | ||
|
||
return r | ||
TOKEN = r['token'] | ||
TOKEN_EXPIRES = r['expires_in'] | ||
return Roboflow(api_key, TOKEN, TOKEN_EXPIRES) | ||
|
||
def export(dataset_name, version_id, format): | ||
global _token | ||
|
||
if not _token: | ||
raise Exception("You must first auth with your API key to call this method.") | ||
class Roboflow(): | ||
def __init__(self, api_key, access_token, token_expires): | ||
self.api_key = api_key | ||
self.access_token = access_token | ||
self.token_expires = token_expires | ||
|
||
response = requests.get(API_URL + "/dataset/" + dataset_name + '/' + str(version_id) + '/' + format, params=({ | ||
"access_token": _token | ||
})) | ||
def list_workspaces(self): | ||
workspaces = requests.get(API_URL + '/workspaces?access_token=' + self.access_token).json() | ||
print(json.dumps(workspaces, indent=2)) | ||
return workspaces | ||
|
||
r = response.json(); | ||
if "error" in r: | ||
raise RuntimeError(response.text) | ||
def load_workspace(self): | ||
pass | ||
|
||
return r | ||
def load(self, dataset_slug): | ||
# TODO: Change endpoint once written | ||
LOAD_ENDPOINT = "ENDPOINT_TO_GET_DATSET_INFO" + dataset_slug | ||
response = requests.get(LOAD_ENDPOINT).json() | ||
return Project(self.api_key, response['dataset_slug'], response['type'], response['exports']) | ||
|
||
def load(dataset, *args): | ||
print(f"loading {dataset} {args}") | ||
def __str__(self): | ||
json_value = {'api_key': self.api_key, 'auth_token': self.access_token, 'token_expires': self.token_expires} | ||
return json.dumps(json_value, indent=2) |