1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
%global _empty_manifest_terminate_build 0
Name: python-detecto
Version: 1.2.2
Release: 1
Summary: Build fully-functioning computer vision models with PyTorch
License: MIT License
URL: https://github.com/alankbi/detecto
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/6f/cf/3959004db3c861d89be02853cde49c5fd10204468dca248cd77a6d89ec43/detecto-1.2.2.tar.gz
BuildArch: noarch
Requires: python3-matplotlib
Requires: python3-opencv-python
Requires: python3-pandas
Requires: python3-torch
Requires: python3-torchvision
Requires: python3-tqdm
%description
[](https://detecto.readthedocs.io/en/latest/?badge=latest)
[](https://pepy.tech/project/detecto)
Detecto is a Python package that allows you to build fully-functioning computer vision and object detection models with just 5 lines of code.
Inference on still images and videos, transfer learning on custom datasets, and serialization of models to files are just a few of Detecto's features.
Detecto is also built on top of PyTorch, allowing an easy transfer of models between the two libraries.
The table below shows a few examples of Detecto's performance:
Still Image | Video
<img src="./assets/apple_orange.png" alt="Detecto still image" width="500px"> | 
# Installation
To install Detecto using pip, run the following command:
`pip3 install detecto`
Installing with pip should download all of Detecto's dependencies automatically.
However, if an issue arises, you can manually download the dependencies listed in the [requirements.txt](requirements.txt) file.
# Usage
The power of Detecto comes from its simplicity and ease of use. Creating and running a pre-trained
[Faster R-CNN ResNet-50 FPN](https://pytorch.org/docs/stable/torchvision/models.html#object-detection-instance-segmentation-and-person-keypoint-detection)
from PyTorch's model zoo takes 4 lines of code:
```python
from detecto.core import Model
from detecto.visualize import detect_video
model = Model() # Initialize a pre-trained model
detect_video(model, 'input_video.mp4', 'output.avi') # Run inference on a video
```
Below are several more examples of things you can do with Detecto:
### Transfer Learning on Custom Datasets
Most of the times, you want a computer vision model that can detect custom objects. With Detecto, you can train a model on a custom dataset with 5 lines of code:
```python
from detecto.core import Model, Dataset
dataset = Dataset('custom_dataset/') # Load images and label data from the custom_dataset/ folder
model = Model(['dog', 'cat', 'rabbit']) # Train to predict dogs, cats, and rabbits
model.fit(dataset)
model.predict(...) # Start using your trained model!
```
### Inference and Visualization
When using a model for inference, Detecto returns predictions in an easy-to-use format and provides several visualization tools:
```python
from detecto.core import Model
from detecto import utils, visualize
model = Model()
image = utils.read_image('image.jpg') # Helper function to read in images
labels, boxes, scores = model.predict(image) # Get all predictions on an image
predictions = model.predict_top(image) # Same as above, but returns only the top predictions
print(labels, boxes, scores)
print(predictions)
visualize.show_labeled_image(image, boxes, labels) # Plot predictions on a single image
images = [...]
visualize.plot_prediction_grid(model, images) # Plot predictions on a list of images
visualize.detect_video(model, 'input_video.mp4', 'output.avi') # Run inference on a video
visualize.detect_live(model) # Run inference on a live webcam
```
### Advanced Usage
If you want more control over how you train your model, Detecto lets you do just that:
```python
from detecto import core, utils
from torchvision import transforms
import matplotlib.pyplot as plt
# Convert XML files to CSV format
utils.xml_to_csv('training_labels/', 'train_labels.csv')
utils.xml_to_csv('validation_labels/', 'val_labels.csv')
# Define custom transforms to apply to your dataset
custom_transforms = transforms.Compose([
transforms.ToPILImage(),
transforms.Resize(800),
transforms.ColorJitter(saturation=0.3),
transforms.ToTensor(),
utils.normalize_transform(),
])
# Pass in a CSV file instead of XML files for faster Dataset initialization speeds
dataset = core.Dataset('train_labels.csv', 'images/', transform=custom_transforms)
val_dataset = core.Dataset('val_labels.csv', 'val_images') # Validation dataset for training
# Create your own DataLoader with custom options
loader = core.DataLoader(dataset, batch_size=2, shuffle=True)
# Use MobileNet instead of the default ResNet
model = core.Model(['car', 'truck', 'boat', 'plane'], model_name='fasterrcnn_mobilenet_v3_large_fpn')
losses = model.fit(loader, val_dataset, epochs=15, learning_rate=0.001, verbose=True)
plt.plot(losses) # Visualize loss throughout training
plt.show()
model.save('model_weights.pth') # Save model to a file
# Directly access underlying torchvision model for even more control
torch_model = model.get_internal_model()
print(type(torch_model))
```
For more examples, visit the [docs](https://detecto.readthedocs.io/), which includes a [quickstart](https://detecto.readthedocs.io/en/latest/usage/quickstart.html) tutorial.
Alternatively, check out the [demo on Colab](https://colab.research.google.com/drive/1ISaTV5F-7b4i2QqtjTa7ToDPQ2k8qEe0).
# API Documentation
The full API documentation can be found at [detecto.readthedocs.io](https://detecto.readthedocs.io/en/latest/api/index.html).
The docs are split into three sections, each corresponding to one of Detecto's modules:
### Core
The [detecto.core](https://detecto.readthedocs.io/en/latest/api/core.html) module contains the central classes of the package: Dataset, DataLoader, and Model.
These are used to read in a labeled dataset and train a functioning object detection model.
### Utils
The [detecto.utils](https://detecto.readthedocs.io/en/latest/api/utils.html) module contains a variety of useful helper functions.
With it, you can read in images, convert XML files into CSV files, apply standard transforms to images, and more.
### Visualize
The [detecto.visualize](https://detecto.readthedocs.io/en/latest/api/visualize.html) module is used to display labeled images, plot predictions, and run object detection on videos.
# Contributing
All issues and pull requests are welcome! To run the code locally, first fork the repository and then run the following commands on your computer:
```bash
git clone https://github.com/<your-username>/detecto.git
cd detecto
# Recommended to create a virtual environment before the next step
pip3 install -r requirements.txt
```
When adding code, be sure to write unit tests and docstrings where necessary.
Tests are located in `detecto/tests` and can be run using pytest:
`python3 -m pytest`
To generate the documentation locally, run the following commands:
```bash
cd docs
make html
```
The documentation can then be viewed at `docs/_build/html/index.html`.
# Contact
Detecto was created by [Alan Bi](https://www.alanbi.com/). Feel free to reach out on [Twitter](https://twitter.com/alankbi) or through [email](mailto:alan.bi326@gmail.com)!
%package -n python3-detecto
Summary: Build fully-functioning computer vision models with PyTorch
Provides: python-detecto
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-detecto
[](https://detecto.readthedocs.io/en/latest/?badge=latest)
[](https://pepy.tech/project/detecto)
Detecto is a Python package that allows you to build fully-functioning computer vision and object detection models with just 5 lines of code.
Inference on still images and videos, transfer learning on custom datasets, and serialization of models to files are just a few of Detecto's features.
Detecto is also built on top of PyTorch, allowing an easy transfer of models between the two libraries.
The table below shows a few examples of Detecto's performance:
Still Image | Video
<img src="./assets/apple_orange.png" alt="Detecto still image" width="500px"> | 
# Installation
To install Detecto using pip, run the following command:
`pip3 install detecto`
Installing with pip should download all of Detecto's dependencies automatically.
However, if an issue arises, you can manually download the dependencies listed in the [requirements.txt](requirements.txt) file.
# Usage
The power of Detecto comes from its simplicity and ease of use. Creating and running a pre-trained
[Faster R-CNN ResNet-50 FPN](https://pytorch.org/docs/stable/torchvision/models.html#object-detection-instance-segmentation-and-person-keypoint-detection)
from PyTorch's model zoo takes 4 lines of code:
```python
from detecto.core import Model
from detecto.visualize import detect_video
model = Model() # Initialize a pre-trained model
detect_video(model, 'input_video.mp4', 'output.avi') # Run inference on a video
```
Below are several more examples of things you can do with Detecto:
### Transfer Learning on Custom Datasets
Most of the times, you want a computer vision model that can detect custom objects. With Detecto, you can train a model on a custom dataset with 5 lines of code:
```python
from detecto.core import Model, Dataset
dataset = Dataset('custom_dataset/') # Load images and label data from the custom_dataset/ folder
model = Model(['dog', 'cat', 'rabbit']) # Train to predict dogs, cats, and rabbits
model.fit(dataset)
model.predict(...) # Start using your trained model!
```
### Inference and Visualization
When using a model for inference, Detecto returns predictions in an easy-to-use format and provides several visualization tools:
```python
from detecto.core import Model
from detecto import utils, visualize
model = Model()
image = utils.read_image('image.jpg') # Helper function to read in images
labels, boxes, scores = model.predict(image) # Get all predictions on an image
predictions = model.predict_top(image) # Same as above, but returns only the top predictions
print(labels, boxes, scores)
print(predictions)
visualize.show_labeled_image(image, boxes, labels) # Plot predictions on a single image
images = [...]
visualize.plot_prediction_grid(model, images) # Plot predictions on a list of images
visualize.detect_video(model, 'input_video.mp4', 'output.avi') # Run inference on a video
visualize.detect_live(model) # Run inference on a live webcam
```
### Advanced Usage
If you want more control over how you train your model, Detecto lets you do just that:
```python
from detecto import core, utils
from torchvision import transforms
import matplotlib.pyplot as plt
# Convert XML files to CSV format
utils.xml_to_csv('training_labels/', 'train_labels.csv')
utils.xml_to_csv('validation_labels/', 'val_labels.csv')
# Define custom transforms to apply to your dataset
custom_transforms = transforms.Compose([
transforms.ToPILImage(),
transforms.Resize(800),
transforms.ColorJitter(saturation=0.3),
transforms.ToTensor(),
utils.normalize_transform(),
])
# Pass in a CSV file instead of XML files for faster Dataset initialization speeds
dataset = core.Dataset('train_labels.csv', 'images/', transform=custom_transforms)
val_dataset = core.Dataset('val_labels.csv', 'val_images') # Validation dataset for training
# Create your own DataLoader with custom options
loader = core.DataLoader(dataset, batch_size=2, shuffle=True)
# Use MobileNet instead of the default ResNet
model = core.Model(['car', 'truck', 'boat', 'plane'], model_name='fasterrcnn_mobilenet_v3_large_fpn')
losses = model.fit(loader, val_dataset, epochs=15, learning_rate=0.001, verbose=True)
plt.plot(losses) # Visualize loss throughout training
plt.show()
model.save('model_weights.pth') # Save model to a file
# Directly access underlying torchvision model for even more control
torch_model = model.get_internal_model()
print(type(torch_model))
```
For more examples, visit the [docs](https://detecto.readthedocs.io/), which includes a [quickstart](https://detecto.readthedocs.io/en/latest/usage/quickstart.html) tutorial.
Alternatively, check out the [demo on Colab](https://colab.research.google.com/drive/1ISaTV5F-7b4i2QqtjTa7ToDPQ2k8qEe0).
# API Documentation
The full API documentation can be found at [detecto.readthedocs.io](https://detecto.readthedocs.io/en/latest/api/index.html).
The docs are split into three sections, each corresponding to one of Detecto's modules:
### Core
The [detecto.core](https://detecto.readthedocs.io/en/latest/api/core.html) module contains the central classes of the package: Dataset, DataLoader, and Model.
These are used to read in a labeled dataset and train a functioning object detection model.
### Utils
The [detecto.utils](https://detecto.readthedocs.io/en/latest/api/utils.html) module contains a variety of useful helper functions.
With it, you can read in images, convert XML files into CSV files, apply standard transforms to images, and more.
### Visualize
The [detecto.visualize](https://detecto.readthedocs.io/en/latest/api/visualize.html) module is used to display labeled images, plot predictions, and run object detection on videos.
# Contributing
All issues and pull requests are welcome! To run the code locally, first fork the repository and then run the following commands on your computer:
```bash
git clone https://github.com/<your-username>/detecto.git
cd detecto
# Recommended to create a virtual environment before the next step
pip3 install -r requirements.txt
```
When adding code, be sure to write unit tests and docstrings where necessary.
Tests are located in `detecto/tests` and can be run using pytest:
`python3 -m pytest`
To generate the documentation locally, run the following commands:
```bash
cd docs
make html
```
The documentation can then be viewed at `docs/_build/html/index.html`.
# Contact
Detecto was created by [Alan Bi](https://www.alanbi.com/). Feel free to reach out on [Twitter](https://twitter.com/alankbi) or through [email](mailto:alan.bi326@gmail.com)!
%package help
Summary: Development documents and examples for detecto
Provides: python3-detecto-doc
%description help
[](https://detecto.readthedocs.io/en/latest/?badge=latest)
[](https://pepy.tech/project/detecto)
Detecto is a Python package that allows you to build fully-functioning computer vision and object detection models with just 5 lines of code.
Inference on still images and videos, transfer learning on custom datasets, and serialization of models to files are just a few of Detecto's features.
Detecto is also built on top of PyTorch, allowing an easy transfer of models between the two libraries.
The table below shows a few examples of Detecto's performance:
Still Image | Video
<img src="./assets/apple_orange.png" alt="Detecto still image" width="500px"> | 
# Installation
To install Detecto using pip, run the following command:
`pip3 install detecto`
Installing with pip should download all of Detecto's dependencies automatically.
However, if an issue arises, you can manually download the dependencies listed in the [requirements.txt](requirements.txt) file.
# Usage
The power of Detecto comes from its simplicity and ease of use. Creating and running a pre-trained
[Faster R-CNN ResNet-50 FPN](https://pytorch.org/docs/stable/torchvision/models.html#object-detection-instance-segmentation-and-person-keypoint-detection)
from PyTorch's model zoo takes 4 lines of code:
```python
from detecto.core import Model
from detecto.visualize import detect_video
model = Model() # Initialize a pre-trained model
detect_video(model, 'input_video.mp4', 'output.avi') # Run inference on a video
```
Below are several more examples of things you can do with Detecto:
### Transfer Learning on Custom Datasets
Most of the times, you want a computer vision model that can detect custom objects. With Detecto, you can train a model on a custom dataset with 5 lines of code:
```python
from detecto.core import Model, Dataset
dataset = Dataset('custom_dataset/') # Load images and label data from the custom_dataset/ folder
model = Model(['dog', 'cat', 'rabbit']) # Train to predict dogs, cats, and rabbits
model.fit(dataset)
model.predict(...) # Start using your trained model!
```
### Inference and Visualization
When using a model for inference, Detecto returns predictions in an easy-to-use format and provides several visualization tools:
```python
from detecto.core import Model
from detecto import utils, visualize
model = Model()
image = utils.read_image('image.jpg') # Helper function to read in images
labels, boxes, scores = model.predict(image) # Get all predictions on an image
predictions = model.predict_top(image) # Same as above, but returns only the top predictions
print(labels, boxes, scores)
print(predictions)
visualize.show_labeled_image(image, boxes, labels) # Plot predictions on a single image
images = [...]
visualize.plot_prediction_grid(model, images) # Plot predictions on a list of images
visualize.detect_video(model, 'input_video.mp4', 'output.avi') # Run inference on a video
visualize.detect_live(model) # Run inference on a live webcam
```
### Advanced Usage
If you want more control over how you train your model, Detecto lets you do just that:
```python
from detecto import core, utils
from torchvision import transforms
import matplotlib.pyplot as plt
# Convert XML files to CSV format
utils.xml_to_csv('training_labels/', 'train_labels.csv')
utils.xml_to_csv('validation_labels/', 'val_labels.csv')
# Define custom transforms to apply to your dataset
custom_transforms = transforms.Compose([
transforms.ToPILImage(),
transforms.Resize(800),
transforms.ColorJitter(saturation=0.3),
transforms.ToTensor(),
utils.normalize_transform(),
])
# Pass in a CSV file instead of XML files for faster Dataset initialization speeds
dataset = core.Dataset('train_labels.csv', 'images/', transform=custom_transforms)
val_dataset = core.Dataset('val_labels.csv', 'val_images') # Validation dataset for training
# Create your own DataLoader with custom options
loader = core.DataLoader(dataset, batch_size=2, shuffle=True)
# Use MobileNet instead of the default ResNet
model = core.Model(['car', 'truck', 'boat', 'plane'], model_name='fasterrcnn_mobilenet_v3_large_fpn')
losses = model.fit(loader, val_dataset, epochs=15, learning_rate=0.001, verbose=True)
plt.plot(losses) # Visualize loss throughout training
plt.show()
model.save('model_weights.pth') # Save model to a file
# Directly access underlying torchvision model for even more control
torch_model = model.get_internal_model()
print(type(torch_model))
```
For more examples, visit the [docs](https://detecto.readthedocs.io/), which includes a [quickstart](https://detecto.readthedocs.io/en/latest/usage/quickstart.html) tutorial.
Alternatively, check out the [demo on Colab](https://colab.research.google.com/drive/1ISaTV5F-7b4i2QqtjTa7ToDPQ2k8qEe0).
# API Documentation
The full API documentation can be found at [detecto.readthedocs.io](https://detecto.readthedocs.io/en/latest/api/index.html).
The docs are split into three sections, each corresponding to one of Detecto's modules:
### Core
The [detecto.core](https://detecto.readthedocs.io/en/latest/api/core.html) module contains the central classes of the package: Dataset, DataLoader, and Model.
These are used to read in a labeled dataset and train a functioning object detection model.
### Utils
The [detecto.utils](https://detecto.readthedocs.io/en/latest/api/utils.html) module contains a variety of useful helper functions.
With it, you can read in images, convert XML files into CSV files, apply standard transforms to images, and more.
### Visualize
The [detecto.visualize](https://detecto.readthedocs.io/en/latest/api/visualize.html) module is used to display labeled images, plot predictions, and run object detection on videos.
# Contributing
All issues and pull requests are welcome! To run the code locally, first fork the repository and then run the following commands on your computer:
```bash
git clone https://github.com/<your-username>/detecto.git
cd detecto
# Recommended to create a virtual environment before the next step
pip3 install -r requirements.txt
```
When adding code, be sure to write unit tests and docstrings where necessary.
Tests are located in `detecto/tests` and can be run using pytest:
`python3 -m pytest`
To generate the documentation locally, run the following commands:
```bash
cd docs
make html
```
The documentation can then be viewed at `docs/_build/html/index.html`.
# Contact
Detecto was created by [Alan Bi](https://www.alanbi.com/). Feel free to reach out on [Twitter](https://twitter.com/alankbi) or through [email](mailto:alan.bi326@gmail.com)!
%prep
%autosetup -n detecto-1.2.2
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-detecto -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Wed May 10 2023 Python_Bot <Python_Bot@openeuler.org> - 1.2.2-1
- Package Spec generated
|