-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Corrected Prophesee Cmake and relaxed serial number requirement * Improved vendor-specific instructions * Added SDL example layer and polished examples * Added device inference * Added CUDA code for tensor buffer * Separated CPU from CUDA build
- Loading branch information
Showing
30 changed files
with
412 additions
and
387 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -29,3 +29,6 @@ result | |
*.dat | ||
*.mp4 | ||
*generated.h | ||
*.deb | ||
release/ | ||
wheelhouse/ |
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
Empty file.
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,4 @@ | ||
matplotlib | ||
norse | ||
pysdl2 | ||
pysdl2-dll |
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 sdl2.ext | ||
|
||
WHITE = (256 << 16 | 256 << 8 | 256) | ||
|
||
def create_sdl_surface(*shape): | ||
sdl2.ext.init() | ||
window = sdl2.ext.Window("AEStream window", shape) | ||
window.show() | ||
# window = sdl2.SDL_CreateWindow("AEStream window", 100, 100, *shape, 0) | ||
|
||
factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE) | ||
renderer = factory.create_sprite_render_system(window) | ||
pixels = sdl2.ext.pixelaccess.pixels2d(renderer) | ||
|
||
return window, pixels | ||
|
||
def events_to_bw(events): | ||
return events.int() * (255 << 16) |
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,47 @@ | ||
# Import the deep learning library, PyTorch | ||
import torch | ||
# Import the spiking neural network library, Norse | ||
import norse | ||
|
||
# Import the DVS camera streaming library, AEstream | ||
from aestream import DVSInput | ||
|
||
# Initialize our canvas | ||
from sdl import create_sdl_surface, events_to_bw | ||
window, pixels = create_sdl_surface(640 * 3, 480) | ||
|
||
# Create horizontal and vertical edge detectors | ||
kernel_size = 9 | ||
gaussian = torch.sigmoid(torch.linspace(-10, 10, kernel_size + 1)) | ||
kernel = (gaussian.diff() - 0.14).repeat(kernel_size, 1) | ||
kernels = torch.stack((kernel, kernel.T)) | ||
convolution = torch.nn.Conv2d(1, 2, kernel_size, padding=12, bias=False, dilation=3) | ||
convolution.weight = torch.nn.Parameter(kernels.unsqueeze(1)) | ||
|
||
# Create Norse network | ||
# - One refractory cell to inhibit pixels | ||
# - One convolutional edge-detection layer | ||
net = norse.torch.SequentialState( | ||
norse.torch.LIFRefracCell(), | ||
convolution, | ||
) | ||
state = None # Start with empty state | ||
|
||
try: | ||
# Start streaming from a DVS camera on USB 2:2 and put them on the CPU | ||
with DVSInput((640, 480)) as stream: | ||
while True: # Loop forever | ||
# Read a tensor (640, 480) tensor from the camera | ||
tensor = stream.read() | ||
# Run the tensor through the network, while updating the state | ||
with torch.inference_mode(): | ||
filtered, state = net(tensor.view(1, 1, 640, 480), state) | ||
|
||
# Render tensors | ||
pixels[0:640] = events_to_bw(tensor) # Input events | ||
pixels[640:640 * 2] = events_to_bw(filtered[0,0]) # First channel | ||
pixels[640 * 2:640 * 3] = events_to_bw(filtered[0,1]) # Second channel | ||
window.refresh() | ||
|
||
finally: | ||
window.close() |
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 |
---|---|---|
@@ -1,51 +1,33 @@ | ||
import time | ||
|
||
# Import the deep learning library, PyTorch | ||
import torch | ||
import norse.torch as snn | ||
import matplotlib | ||
|
||
matplotlib.use("Qt5Agg") | ||
import matplotlib.animation as animation | ||
import matplotlib.pyplot as plt | ||
# Import the spiking neural network library, Norse | ||
import norse | ||
|
||
# Import the DVS camera streaming library, AEstream | ||
from aestream import DVSInput | ||
|
||
## Example modified from: https://matplotlib.org/stable/tutorials/advanced/blitting.html | ||
|
||
# Initialize our canvas | ||
fig, (ax1, ax2) = plt.subplots(1, 2) | ||
image1 = ax1.imshow(torch.zeros(260, 346), cmap="gray", vmin=0, vmax=1) | ||
image2 = ax2.imshow(torch.zeros(260, 346), cmap="gray", vmin=0, vmax=2) | ||
plt.show(block=False) | ||
plt.pause(0.1) | ||
bg = fig.canvas.copy_from_bbox(fig.bbox) | ||
ax1.draw_artist(image1) | ||
ax2.draw_artist(image2) | ||
fig.canvas.blit(fig.bbox) | ||
from sdl import create_sdl_surface, events_to_bw | ||
window, pixels = create_sdl_surface(640 * 2, 480) | ||
|
||
# Initialize PyTorch network | ||
net = snn.LICell().cuda() | ||
state = None | ||
# Create a simple Norse leaky integrator | ||
net = norse.torch.LICell(p=norse.torch.LIParameters(tau_syn_inv=100)) | ||
state = None # Start with empty state | ||
|
||
# Start streaming from a DVS camera on USB 2:2 and put them on the GPU | ||
try: | ||
with DVSInput(2, 2, (640, 480), device="cuda") as stream: | ||
while True: | ||
# Read a tensor (346, 260) tensor from the camera | ||
tensor = stream.read() | ||
# Start streaming from a DVS camera on USB 2:2 and put them on the CPU | ||
with DVSInput((640, 480), device="cuda") as stream: | ||
while True: # Loop forever | ||
# Read a tensor (640, 480) tensor from the camera | ||
tensor = stream.read().cpu() | ||
# Run the tensor through the network, while updating the state | ||
with torch.inference_mode(): | ||
filtered, state = net(tensor.view(1, 1, 346, 260), state) | ||
filtered, state = net(tensor.view(1, 640, 480), state) | ||
|
||
# Redraw figure | ||
fig.canvas.restore_region(bg) | ||
image1.set_data(tensor.T.cpu().numpy()) | ||
image2.set_data(filtered.squeeze().T.cpu().numpy()) | ||
ax1.draw_artist(image1) | ||
ax2.draw_artist(image2) | ||
fig.canvas.blit(fig.bbox) | ||
fig.canvas.flush_events() | ||
# Render tensors | ||
pixels[0:640] = events_to_bw(tensor) # Input events | ||
pixels[640:640 * 2] = events_to_bw(filtered[0]) # First channel | ||
window.refresh() | ||
|
||
# Pause to only loop 100 times per second | ||
plt.pause(0.01) | ||
except Exception as e: | ||
print("Error", e) | ||
finally: | ||
window.close() |
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
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 |
---|---|---|
@@ -1,37 +1,22 @@ | ||
import time | ||
|
||
import torch | ||
import matplotlib | ||
|
||
matplotlib.use("Qt5Agg") | ||
import matplotlib.animation as animation | ||
import matplotlib.pyplot as plt | ||
|
||
import torch # Torch is needed to import c10 (Core TENsor) context | ||
from aestream import DVSInput | ||
import sdl | ||
|
||
## Example modified from: https://matplotlib.org/stable/tutorials/advanced/blitting.html | ||
# Define our camera resolution | ||
resolution = (640, 480) | ||
|
||
# Initialize our canvas | ||
fig, ax = plt.subplots() | ||
image = ax.imshow(torch.zeros(260, 346), cmap="gray", vmin=0, vmax=1) | ||
plt.show(block=False) | ||
plt.pause(0.1) | ||
bg = fig.canvas.copy_from_bbox(fig.bbox) | ||
ax.draw_artist(image) | ||
fig.canvas.blit(fig.bbox) | ||
window, pixels = sdl.create_sdl_surface(*resolution) | ||
|
||
# Start streaming from a DVS camera on USB 2:3 | ||
with DVSInput(2, 2, (640, 480)) as stream: | ||
# Start streaming from a DVS camera on USB 2:2 | ||
with DVSInput(resolution, device="cuda") as stream: | ||
while True: | ||
# Read a tensor (346, 260) tensor from the camera | ||
tensor = stream.read() | ||
|
||
# Redraw figure | ||
fig.canvas.restore_region(bg) | ||
image.set_data(tensor.T.numpy()) | ||
ax.draw_artist(image) | ||
fig.canvas.blit(fig.bbox) | ||
fig.canvas.flush_events() | ||
|
||
# Pause to only loop 10 times per second | ||
plt.pause(0.01) | ||
# Read a tensor (640, 480) tensor from the camera | ||
tensor = stream.read().cpu() | ||
#1tensor = torch.randn(640, 480).float() + 2 | ||
|
||
# Render pixels | ||
pixels[:] = sdl.events_to_bw(tensor) | ||
window.refresh() | ||
time.sleep(0.01) |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
ninja | ||
numpy | ||
torch>=1.9 | ||
torch>=1.10 |
Oops, something went wrong.