-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
886 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,6 @@ | ||
# __init__.py | ||
__version__ = "1.0.1" | ||
|
||
from sightseer.sightseer import Sightseer | ||
from sightseer.zoo import * | ||
from sightseer.proc import * |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,18 @@ | ||
import pathlib | ||
from setuptools import setup | ||
|
||
HERE = pathlib.Path(__file__).parent | ||
README = (HERE / "README.md").read_text() | ||
|
||
setup( | ||
name="sightseer", | ||
version="1.0.1", | ||
description="State-of-the-art Computer Vision and Object Detection for TensorFlow.", | ||
long_description=README, | ||
long_description_content_type="text/markdown", | ||
author="", | ||
author_email="", | ||
license="ASF", | ||
packages=["sightseer"], | ||
zip_safe=False | ||
) |
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,116 @@ | ||
Metadata-Version: 2.1 | ||
Name: sightseer | ||
Version: 1.0.1 | ||
Summary: State-of-the-art Computer Vision and Object Detection for TensorFlow. | ||
Home-page: UNKNOWN | ||
Author: | ||
Author-email: | ||
License: ASF | ||
Description: <p align="center"> | ||
<br> | ||
<img src="./Assets/logo.png" width=200> | ||
<br> | ||
<p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/rish-16/sight/blob/master/LICENSE"> | ||
<img alt="AUR license" src="https://img.shields.io/badge/License-Apache%202.0-yellow.svg"> | ||
</a> | ||
</p> | ||
|
||
<h3 align="center"> | ||
<p>State-of-the-art Computer Vision and Object Detection for TensorFlow.</p> | ||
</h3> | ||
|
||
*Sight* provides state-of-the-art general-purpose architectures (YOLO9000, MaskRCNN, Fast/Faster RCNN, SSD...) for Computer Vision and Object Detection tasks with 30+ pretrained models written in TensorFlow 1.15. | ||
|
||
## Installation | ||
|
||
`sight` is written in Python 3.5+ and TensorFlow 1.15. | ||
|
||
Ideally, `sight` should be installed in a [virtual environments](https://docs.python.org/3/library/venv.html). If you're unfamiliar with Python virtual environments, check out this [tutorial](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) on getting started. | ||
|
||
### Via PyPi | ||
|
||
To use `sight`, you must first have TensorFlow installed. To do so, follow the instructions on the [TensorFlow installation page](https://www.tensorflow.org/install/pip?lang=python3). | ||
|
||
When your virtual environment is set up with TensorFlow, you can install `sight` using `pip`: | ||
|
||
```bash | ||
pip install sight | ||
``` | ||
|
||
### From Source | ||
|
||
Again, to install from source, you need TensorFlow 1.15 and above running in a virtual environment. You can install the package by cloning the repo and installing the dependencies: | ||
|
||
```bash | ||
git clone https://github.com/rish-16/sight | ||
cd sight | ||
pip install . | ||
``` | ||
|
||
### Model Architectures | ||
|
||
1. YOLOv3 (Darknet by Joseph Redmon) | ||
2. Mask R-CNN (Facebook AI Research) | ||
|
||
## Usage | ||
|
||
<strong>1a. Loading images</strong> | ||
|
||
```python | ||
from sight import Sightseer | ||
|
||
ss = Sightseer() | ||
image = ss.load_image("path/to/image") | ||
``` | ||
|
||
<strong>1b. Loading videos</strong> | ||
|
||
```python | ||
from sight import Sightseer | ||
|
||
ss = Sightseer() | ||
frames = ss.load_vidsource("path/to/video", return_data=True) | ||
``` | ||
|
||
<strong>1c. Loading webcam footage</strong> | ||
|
||
```python | ||
from sight import Sightseer | ||
|
||
ss = Sightseer() | ||
image = ss.load_webcam() | ||
``` | ||
|
||
<strong>1d. Loading screen grab footage</strong> | ||
|
||
```python | ||
from sight import Sightseer | ||
|
||
ss = Sightseer() | ||
image = ss.screen_grab() | ||
``` | ||
|
||
<strong>2. Using models from `sight.zoo`</strong> | ||
|
||
Once installed, any model offered by `sight` can be accessed in less than 10 lines of code. For instance, the code to use the YOLOv3 (Darknet) model is as follows: | ||
|
||
```python | ||
from sight import Sightseer | ||
from sight.zoo import YOLOv3Client | ||
|
||
yolo = YOLOv3Client() | ||
yolo.load_model() # downloads weights | ||
|
||
# loading images from local system | ||
ss = Sightseer("path/to/img") | ||
image = ss.load_image() | ||
|
||
# returns array of labels, confidence, and bounding box info | ||
preds, pred_img = yolo.predict(image, return_image=True) | ||
ss.render_image(pred_img) | ||
``` | ||
Platform: UNKNOWN | ||
Description-Content-Type: text/markdown |
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,12 @@ | ||
README.md | ||
setup.py | ||
sightseer/__init__.py | ||
sightseer/blocks.py | ||
sightseer/proc.py | ||
sightseer/sightseer.py | ||
sightseer/zoo.py | ||
sightseer.egg-info/PKG-INFO | ||
sightseer.egg-info/SOURCES.txt | ||
sightseer.egg-info/dependency_links.txt | ||
sightseer.egg-info/not-zip-safe | ||
sightseer.egg-info/top_level.txt |
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 @@ | ||
|
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 @@ | ||
|
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 @@ | ||
sightseer |
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,6 @@ | ||
# __init__.py | ||
__version__ = "1.0.1" | ||
|
||
from sightseer.sightseer import Sightseer | ||
from sightseer.zoo import * | ||
from sightseer.proc import * |
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 @@ | ||
import struct | ||
import numpy as np | ||
import tensorflow as tf | ||
from tensorflow.keras.layers import Conv2D, ZeroPadding2D, BatchNormalization, LeakyReLU, add | ||
|
||
class BoundingBox(object): | ||
def __init__(self, xmin, ymin, xmax, ymax, objectness=None, classes=None): | ||
self.xmin = xmin | ||
self.ymin = ymin | ||
self.xmax = xmax | ||
self.ymax = ymax | ||
|
||
self.objectness = objectness | ||
self.classes = classes | ||
|
||
self.label = -1 | ||
self.confidence = -1 | ||
|
||
def get_label(self): | ||
if self.label == -1: | ||
self.label = np.argmax(self.classes) | ||
return self.label | ||
|
||
def get_confidence(self): | ||
if self.confidence == -1: | ||
self.confidence = self.classes[self.get_label()] | ||
return self.confidence | ||
|
||
class SightLoader(): | ||
def __init__(self, weights_path): | ||
""" | ||
Weights loading framework for all Sight models | ||
""" | ||
with open(weights_path, 'rb') as wf: | ||
major, = struct.unpack('i', wf.read(4)) | ||
minor, = struct.unpack('i', wf.read(4)) | ||
revision, = struct.unpack('i', wf.read(4)) | ||
|
||
if (major*10+ minor) >= 2 and major < 1000 and minor < 1000: | ||
wf.read(8) | ||
else: | ||
wf.read(4) | ||
|
||
transpose = (major > 1000) or (minor > 1000) | ||
|
||
binary = wf.read() | ||
|
||
self.offset = 0 | ||
self.all_weights = np.frombuffer(binary, dtype="float32") | ||
|
||
def read_bytes(self, chunk_size): | ||
self.offset = self.offset + chunk_size | ||
return self.all_weights[self.offset - chunk_size:self.offset] | ||
|
||
def load_weights(self, model, verbose=True): | ||
for i in range(106): # standard darknet layer count | ||
try: | ||
conv_layer = model.get_layer("conv_" + str(i)) | ||
|
||
if verbose: | ||
print ("Loading Convolution #{}".format(i)) | ||
|
||
if i not in [81, 93, 105]: | ||
norm_layer = model.get_layer("bnorm_" + str(i)) | ||
|
||
size = np.prod(norm_layer.get_weights()[0].shape) | ||
|
||
beta = self.read_bytes(size) | ||
gamma = self.read_bytes(size) | ||
mean = self.read_bytes(size) | ||
var = self.read_bytes(size) | ||
|
||
weights = norm_layer.set_weights([gamma, beta, mean, var]) | ||
|
||
if len(conv_layer.get_weights()) > 1: | ||
bias = self.read_bytes(np.prod(conv_layer.get_weights()[1].shape)) | ||
kernel = self.read_bytes(np.prod(conv_layer.get_weights()[0].shape)) | ||
|
||
kernel = kernel.reshape(list(reversed(conv_layer.get_weights()[0].shape))) | ||
kernel = kernel.transpose([2, 3, 1, 0]) | ||
conv_layer.set_weights([kernel, bias]) | ||
else: | ||
kernel = self.read_bytes(np.prod(conv_layer.get_weights()[0].shape)) | ||
kernel = kernel.reshape(list(reversed(conv_layer.get_weights()[0].shape))) | ||
kernel = kernel.transpose([2, 3, 1, 0]) | ||
conv_layer.set_weights([kernel]) | ||
|
||
except ValueError: | ||
if verbose: | ||
print ("No Convolution #{}".format(i)) | ||
else: | ||
pass | ||
|
||
if verbose: | ||
print ("Finished loading weights into model. Predicting on input data...") | ||
|
||
def reset_offset(self): | ||
self.offset = 0 | ||
|
||
class ConvBlock(): | ||
def get_conv_block(inp, convs, skip=True): | ||
x = inp | ||
count = 0 | ||
|
||
for conv in convs: | ||
if count == (len(convs) - 2) and skip: | ||
skip_conn = x | ||
count += 1 | ||
|
||
if conv['stride'] > 1: x = ZeroPadding2D(((1,0),(1,0)))(x) | ||
|
||
x = Conv2D(conv['filter'], | ||
conv['kernel'], | ||
strides=conv['stride'], | ||
padding="valid" if conv['stride']>1 else "same", | ||
name="conv_"+str(conv['layer_idx']), | ||
use_bias=False if conv['bnorm'] else True)(x) | ||
|
||
if conv['bnorm']: x = BatchNormalization(epsilon=0.001, name="bnorm_"+str(conv['layer_idx']))(x) | ||
|
||
if conv['leaky']: x = LeakyReLU(alpha=0.1, name="leaky_"+str(conv['layer_idx']))(x) | ||
|
||
return add([skip_conn, x]) if skip else x |
Oops, something went wrong.