Skip to content

Commit 79bba99

Browse files
authored
Merge pull request #215 from roboflow/newcommands
Add new commands to the CLI
2 parents c5e1838 + 2659ef7 commit 79bba99

24 files changed

+604
-512
lines changed

CLI-COMMANDS.md

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# The roboflow-python command line
2+
This has the same capabilities of the [roboflow node cli](https://www.npmjs.com/package/roboflow-cli) so that our users don't need to install two different tools.
3+
4+
## See available commands
5+
6+
```bash
7+
$ roboflow --help
8+
```
9+
10+
```
11+
usage: roboflow [-h] {login,download,upload,import,infer,project,workspace} ...
12+
13+
Welcome to the roboflow CLI: computer vision at your fingertips 🪄
14+
15+
options:
16+
-h, --help show this help message and exit
17+
18+
subcommands:
19+
{login,download,upload,import,infer,project,workspace}
20+
login Log in to Roboflow
21+
download Download a dataset version from your workspace or Roboflow Universe.
22+
upload Upload a single image to a dataset
23+
import Import a dataset from a local folder
24+
infer perform inference on an image
25+
project project related commands. type 'roboflow project' to see detailed command help
26+
workspace workspace related commands. type 'roboflow workspace' to see detailed command help
27+
```
28+
29+
## Authentication
30+
31+
You need to authenticate first
32+
33+
```bash
34+
$ roboflow login
35+
```
36+
37+
```
38+
visit https://app.roboflow.com/auth-cli to get your authentication token.
39+
Paste the authentication token here:
40+
```
41+
Open that link on your browser, get the token, paste it on the terminal.
42+
The credentials get saved to `~/.config/roboflow/config.json`
43+
44+
## Display help usage for other commands
45+
46+
"How do I download stuff?"
47+
48+
```bash
49+
$ roboflow download --help
50+
```
51+
```
52+
usage: roboflow download [-h] [-f FORMAT] [-l LOCATION] datasetUrl
53+
54+
positional arguments:
55+
datasetUrl Dataset URL (e.g., `roboflow-100/cells-uyemf/2`)
56+
57+
options:
58+
-h, --help show this help message and exit
59+
-f FORMAT Specify the format to download the version. Available options: [coco, yolov5pytorch, yolov7pytorch, my-yolov6, darknet,
60+
voc, tfrecord, createml, clip, multiclass, coco-segmentation, yolo5-obb, png-mask-semantic, yolov8]
61+
-l LOCATION Location to download the dataset
62+
```
63+
64+
"How do I import a dataset into my workspace?"
65+
66+
```bash
67+
$ roboflow import --help
68+
```
69+
70+
```
71+
usage: roboflow import [-h] [-w WORKSPACE] [-p PROJECT] [-c CONCURRENCY] [-f FORMAT] folder
72+
73+
positional arguments:
74+
folder filesystem path to a folder that contains your dataset
75+
76+
options:
77+
-h, --help show this help message and exit
78+
-w WORKSPACE specify a workspace url or id (will use default workspace if not specified)
79+
-p PROJECT project will be created if it does not exist
80+
-c CONCURRENCY how many image uploads to perform concurrently (default: 10)
81+
-f FORMAT dataset format. Valid options are [voc, yolov8, yolov5, auto] (use auto for autodetect)
82+
```
83+
84+
## Example: download dataset
85+
86+
Download [Joseph's chess dataset](https://universe.roboflow.com/joseph-nelson/chess-pieces-new/dataset/25) from Roboflow Universe in VOC format:
87+
88+
```bash
89+
$ roboflow download -f voc -l ~/tmp/chess joseph-nelson/chess-pieces-new/25
90+
```
91+
```
92+
loading Roboflow workspace...
93+
loading Roboflow project...
94+
Downloading Dataset Version Zip in /Users/tony/tmp/chess to voc:: 100%|██████████████████████████| 19178/19178 [00:01<00:00, 10424.62it/s]
95+
96+
Extracting Dataset Version Zip to /Users/tony/tmp/chess in voc:: 100%|██████████████████████████████| 1391/1391 [00:00<00:00, 8992.30it/s]
97+
```
98+
```bash
99+
$ ls -lh ~/tmp/chess
100+
total 16
101+
-rw-r--r--@ 1 tony staff 1.8K Jan 5 10:32 README.dataset.txt
102+
-rw-r--r--@ 1 tony staff 562B Jan 5 10:32 README.roboflow.txt
103+
drwxr-xr-x@ 60 tony staff 1.9K Jan 5 10:32 test
104+
drwxr-xr-x@ 1214 tony staff 38K Jan 5 10:32 train
105+
drwxr-xr-x@ 118 tony staff 3.7K Jan 5 10:32 valid
106+
```
107+
108+
## Example: list workspaces
109+
List the workspaces you have access to
110+
111+
```bash
112+
$ roboflow workspace list
113+
```
114+
115+
```
116+
tonyprivate
117+
link: https://app.roboflow.com/tonyprivate
118+
id: tonyprivate
119+
120+
wolfodorpythontests
121+
link: https://app.roboflow.com/wolfodorpythontests
122+
id: wolfodorpythontests
123+
124+
test minimize
125+
link: https://app.roboflow.com/test-minimize
126+
id: test-minimize
127+
```
128+
129+
## Example: get workspace details
130+
131+
```bash
132+
$ roboflow workspace get tonyprivate
133+
```
134+
135+
```
136+
{
137+
"workspace": {
138+
"name": "tonyprivate",
139+
"url": "tonyprivate",
140+
"members": 4,
141+
"projects": [
142+
{
143+
"id": "tonyprivate/annotation-upload",
144+
"type": "object-detection",
145+
"name": "annotation-upload",
146+
"created": 1685199749.708,
147+
"updated": 1695910515.48,
148+
"images": 1,
149+
(...)
150+
}
151+
]
152+
}
153+
}
154+
```
155+
156+
## Example: list projects
157+
158+
```bash
159+
roboflow project list -w tonyprivate
160+
```
161+
```
162+
annotation-upload
163+
link: https://app.roboflow.com/tonyprivate/annotation-upload
164+
id: tonyprivate/annotation-upload
165+
type: object-detection
166+
versions: 0
167+
images: 1
168+
classes: dict_keys(['0', 'Rabbits1', 'Rabbits2', 'minion1', 'minion0', '5075E'])
169+
170+
hand-gestures
171+
link: https://app.roboflow.com/tonyprivate/hand-gestures-fsph8
172+
id: tonyprivate/hand-gestures-fsph8
173+
type: object-detection
174+
versions: 5
175+
images: 387
176+
classes: dict_keys(['zero', 'four', 'one', 'two', 'five', 'three', 'Guard'])
177+
```
178+
179+
## Example: get project details
180+
181+
```bash
182+
roboflow project get -w tonyprivate annotation-upload
183+
```
184+
```
185+
{
186+
"workspace": {
187+
"name": "tonyprivate",
188+
"url": "tonyprivate",
189+
"members": 4
190+
},
191+
"project": {
192+
"id": "tonyprivate/annotation-upload",
193+
"type": "object-detection",
194+
"name": "annotation-upload",
195+
"created": 1685199749.708,
196+
"updated": 1695910515.48,
197+
"images": 1,
198+
(...)
199+
},
200+
"versions": []
201+
}
202+
```
203+
204+
## Example: run inference
205+
206+
If your project has a trained model (or you are using a dataset from Roboflow Universe that has a trained model), you can run inference from the command line.
207+
208+
Let's use [Rock-Paper-Scissors sample public dataset]([url](https://universe.roboflow.com/roboflow-58fyf/rock-paper-scissors-sxsw/model/11)) from Roboflow universe
209+
210+
(In my case, `~/scissors.png` is me holding two fingers to the camera, you can use your own image file ;-))
211+
212+
```bash
213+
roboflow infer -w roboflow-58fyf -m rock-paper-scissors-sxsw/11 ~/scissors.png
214+
```
215+
```
216+
{
217+
"x": 1230.0,
218+
"y": 814.5,
219+
"width": 840.0,
220+
"height": 1273.0,
221+
"confidence": 0.8817358016967773,
222+
"class": "Scissors",
223+
"class_id": 2,
224+
"image_path": "/Users/tony/scissors.png",
225+
"prediction_type": "ObjectDetectionModel"
226+
}
227+
```

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ check_code_quality:
1313
# stop the build if there are Python syntax errors or undefined names
1414
flake8 $(check_dirs) --count --select=E9,F63,F7,F82 --show-source --statistics
1515
# exit-zero treats all errors as warnings. E203 for black, E501 for docstring, W503 for line breaks before logical operators
16-
flake8 $(check_dirs) --count --max-line-length=88 --exit-zero --ignore=D --extend-ignore=E203,E501,W503 --statistics
16+
flake8 $(check_dirs) --count --max-line-length=120 --exit-zero --ignore=D --extend-ignore=E203,E501,W503 --statistics
1717

1818
publish:
1919
python setup.py sdist bdist_wheel

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ pip install roboflow
5858
```
5959
</details>
6060

61+
<details>
62+
<summary>Command line tool</summary>
63+
64+
By installing roboflow python package you can use some of its functionality in the command line (without having to write python code).
65+
See [CLI-COMMANDS.md](CLI-COMMANDS.md)
66+
</details>
67+
68+
6169
## 🚀 Getting Started
6270

6371
To use the Roboflow Python package, you first need to authenticate with your Roboflow account. You can do this by running the following command:

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66
[tool.flake8]
77
exclude = ".venv"
88
max-complexity = 10
9-
max-line-length = 88
9+
max-line-length = 120
1010
extend-ignore = """
1111
W503,
1212
E203,
@@ -17,8 +17,11 @@ per-file-ignores = """
1717
__init__.py: F401
1818
"""
1919

20+
[tool.black]
21+
line-length = 120
22+
2023
[tool.isort]
21-
line_length = 88
24+
line_length = 120
2225
profile = "black"
2326

2427
[tool.bandit]
@@ -115,7 +118,7 @@ exclude = [
115118
]
116119

117120
# Same as Black.
118-
line-length = 88
121+
line-length = 120
119122

120123
# Allow unused variables when underscore-prefixed.
121124
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

0 commit comments

Comments
 (0)