Skip to content

Commit

Permalink
Featgroup (#111)
Browse files Browse the repository at this point in the history
* Fix the clamping scheme and write out the last partial ADU

* Visualize clusters

* Draw rectangle for feature clusters

* Improve c_thresh adjustment

* Add options to viz

* Cleanup and docs

* Remove opencv ci and get tests passing

---------

Co-authored-by: Andrew <[email protected]>
  • Loading branch information
ac-freeman and Andrew authored Mar 15, 2024
1 parent 85694a7 commit 7520ab9
Show file tree
Hide file tree
Showing 39 changed files with 662 additions and 404 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/rust_action_test_and_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
toolchain: nightly
override: true

- name: Install OpenCV
run: sudo apt-get install -y --fix-missing libopencv-dev libopencv-calib3d-dev libopencv-contrib-dev libopencv-features2d-dev libopencv-highgui-dev libopencv-imgcodecs-dev libopencv-objdetect-dev libopencv-shape-dev libopencv-stitching-dev libopencv-superres-dev libopencv-video-dev libopencv-videoio-dev libopencv-videostab-dev libopencv4.2-java libopencv-calib3d4.2 libopencv-contrib4.2 libopencv-features2d4.2 libopencv-highgui4.2 libopencv-imgcodecs4.2 libopencv-videoio4.2 libgdal26 libodbc1 libssl-dev alsa-utils libasound2-dev portaudio19-dev build-essential libpulse-dev libdbus-1-dev libudev-dev libatk1.0-dev libgtk-3-dev libavfilter-dev libavdevice-dev
- name: Install AV dependencies
run: sudo apt-get install -y --fix-missing libgdal26 libodbc1 libssl-dev alsa-utils libasound2-dev portaudio19-dev build-essential libpulse-dev libdbus-1-dev libudev-dev libatk1.0-dev libgtk-3-dev libavfilter-dev libavdevice-dev

- name: Clang
run: sudo apt-get install -y clang && sudo ln -s libclang.so.1 /usr/lib/llvm-10/lib/libclang.so
Expand All @@ -38,7 +38,7 @@ jobs:
run: sudo apt-get install -y portaudio19-dev build-essential libpulse-dev libdbus-1-dev pkg-config libx11-dev libatk1.0-dev libgtk-3-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libwayland-dev libxkbcommon-dev ffmpeg

- name: Check project
run: cargo check -p adder-codec-core -p adder-codec-rs -p adder-info -p adder-to-dvs -p adder-viz --features "compression open-cv"
run: cargo check -p adder-codec-core -p adder-codec-rs -p adder-info -p adder-to-dvs -p adder-viz --features "compression"

- name: Build binaries for testing
run: cargo build -p adder-info
Expand Down Expand Up @@ -68,17 +68,9 @@ jobs:
run: choco install -y llvm
shell: bash

# - name: Install OpenCV
# run: choco install -y opencv --version "$OPENCV_VERSION"
# shell: bash

- name: Test project
run: |
export PATH="/C/Program Files/LLVM/bin:$PATH"
export LIBCLANG_PATH="/C/Program Files/LLVM/bin"
export PATH="/C/tools/opencv/build/x64/vc15/bin:$PATH"
export OPENCV_LINK_PATHS="/C/tools/opencv/build/x64/vc15/lib"
export OPENCV_LINK_LIBS="opencv_world${OPENCV_VERSION//./}"
export OPENCV_INCLUDE_PATHS="/C/tools/opencv/build/include"
cargo test -p adder-codec-core --features "compression"
shell: bash
6 changes: 3 additions & 3 deletions .idea/runConfigurations/ADDER_to_DVS_release.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/runConfigurations/Check.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/runConfigurations/Test_stable.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/_template__of_Cargo_Command.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ opt-level = 3
panic = "unwind"

[profile.dev.package."adder-codec-rs"]
opt-level = 3
opt-level = 1
overflow-checks = false
#panic = "abort"

Expand All @@ -27,7 +27,7 @@ overflow-checks = false


[profile.dev.package."*"]
opt-level = 3
opt-level = 1

[profile.dev]
opt-level = 1
Expand Down
10 changes: 5 additions & 5 deletions adder-codec-core/src/codec/compressed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ mod tests {
encoder.flush_writer().unwrap();
let writer = encoder.close_writer().unwrap().unwrap();

dbg!(writer.len());
// It should still be just the header, because we haven't integrated enough events
// to write out a frame (haven't reached DeltaT_max)
assert_eq!(writer.len(), meta.header_size);
let tmp_len = writer.len();

// We should have compressed the partial ADU, and thus have more than the header size
assert!(writer.len() > meta.header_size);

let output = crate::codec::compressed::stream::CompressedOutput::new(meta, Vec::new());
let mut encoder = Encoder::new_compressed(
Expand All @@ -75,6 +75,6 @@ mod tests {
let writer = encoder.close_writer().unwrap().unwrap();

// Now we've exceeded the DeltaT_max, so we should have written out a frame
assert!(writer.len() > meta.header_size);
assert!(writer.len() > tmp_len);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct EventAdu {
/// How many dt_ref intervals the whole adu spans
pub(crate) num_intervals: usize,

skip_adu: bool,
pub(crate) skip_adu: bool,

cube_to_write_count: u16,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl ComponentCompression for EventCube {
+ ((t_residual as i64) << bitshift_amt as i64))
as AbsoluteT;
}
debug_assert!(event.t < 2_u32.pow(29));
debug_assert!(event.t < 2_u32.pow(31));

*init = *event;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pub mod event_adu;
/// An `EventCube` has many compressed events
mod event_cube;

/// Width and height (same number) of a block
pub const BLOCK_SIZE: usize = 16;
pub const BLOCK_SIZE_AREA: usize = BLOCK_SIZE * BLOCK_SIZE;
33 changes: 29 additions & 4 deletions adder-codec-core/src/codec/compressed/stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::codec::{CodecError, CodecMetadata, EncoderOptions, ReadCompression, WriteCompression};
use bitstream_io::{BigEndian, BitRead, BitReader, BitWrite, BitWriter};
use std::io::{BufWriter, Cursor, Read, Seek, SeekFrom, Write};
use std::io::{Cursor, Read, Seek, SeekFrom, Write};

use crate::codec::compressed::source_model::event_structure::event_adu::EventAdu;
use crate::codec::compressed::source_model::HandleEvent;
Expand Down Expand Up @@ -73,6 +73,30 @@ impl<W: Write> WriteCompression<W> for CompressedOutput<W> {
}

fn into_writer(&mut self) -> Option<W> {
if !self.adu.skip_adu {
if let Some(stream) = &mut self.stream {
dbg!("compressing partial last adu");
let mut temp_stream = BitWriter::endian(Vec::new(), BigEndian);

let parameters = self.options.crf.get_parameters();

// Compress the Adu. This also writes the EOF symbol and flushes the encoder
self.adu
.compress(&mut temp_stream, parameters.c_thresh_max)
.ok()?;

let written_data = temp_stream.into_writer();

// Write the number of bytes in the compressed Adu as the 32-bit header for this Adu
stream
.write_bytes(&(written_data.len() as u32).to_be_bytes())
.ok()?;

// Write the temporary stream to the actual stream
stream.write_bytes(&written_data).ok()?;
}
}

let tmp = self.stream.take();

tmp.map(|bitwriter| bitwriter.into_writer())
Expand All @@ -89,6 +113,7 @@ impl<W: Write> WriteCompression<W> for CompressedOutput<W> {
fn ingest_event(&mut self, event: Event) -> Result<(), CodecError> {
// Check that the event fits within the Adu's time range
if event.t > self.adu.start_t + (self.adu.dt_ref * self.adu.num_intervals as DeltaT) {
// dbg!("compressing adu");
// If it doesn't, compress the events and reset the Adu
if let Some(stream) = &mut self.stream {
// Create a temporary u8 stream to write the arithmetic-coded data to
Expand Down Expand Up @@ -204,7 +229,7 @@ impl<R: Read + Seek> ReadCompression<R> for CompressedInput<R> {
adu.decompress(&mut adu_stream);

let duration = start.elapsed();
println!("Decompressed Adu in {:?} ns", duration.as_nanos());
// println!("Decompressed Adu in {:?} ns", duration.as_nanos());
}
// Then return the next event from the queue
match adu.digest_event() {
Expand Down Expand Up @@ -249,7 +274,7 @@ mod tests {
use std::io;

/// Test the creation a CompressedOutput and writing a bunch of events to it but NOT getting
/// to the time where we compress the Adu
/// to the time where we have a full Adu. It will compress the last partial ADU.
#[test]
fn test_compress_empty() -> Result<(), Box<dyn Error>> {
use crate::codec::compressed::stream::CompressedOutput;
Expand Down Expand Up @@ -301,7 +326,7 @@ mod tests {
}

let output = compressed_output.into_writer().unwrap().into_inner();
assert!(output.is_empty());
assert!(!output.is_empty());
Ok(())
}

Expand Down
2 changes: 0 additions & 2 deletions adder-codec-core/src/codec/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::codec::Magic;
use crate::codec::{CodecError, CodecMetadata, EncoderType, ReadCompression, ReadCompressionEnum};
use crate::SourceType::*;
use crate::{Event, PlaneSize, SourceCamera, SourceType};
Expand All @@ -8,7 +7,6 @@ use crate::{Event, PlaneSize, SourceCamera, SourceType};
#[cfg(feature = "compression")]
use crate::codec::compressed::stream::CompressedInput;

use crate::codec::encoder::Encoder;
use crate::codec::header::{
EventStreamHeader, EventStreamHeaderExtensionV1, EventStreamHeaderExtensionV2,
EventStreamHeaderExtensionV3, MAGIC_COMPRESSED,
Expand Down
1 change: 1 addition & 0 deletions adder-codec-core/src/codec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub mod empty;
pub mod encoder;
mod header;

/// Control the quality of ADDER transcoding and compression in a predictable manner
pub mod rate_controller;
/// Raw codec utilities
pub mod raw;
Expand Down
1 change: 1 addition & 0 deletions adder-codec-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub enum SourceCamera {
Asint,
}

/// Is the given source camera a framed source?
pub fn is_framed(source_camera: SourceCamera) -> bool {
matches!(
source_camera,
Expand Down
6 changes: 4 additions & 2 deletions adder-codec-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exclude = [
default-run = "adder_simulproc"

[features]
default = ["transcoder"]
default = ["compression"]
transcoder = ["dep:fast-math", "adder-codec-core"]
compression = ["dep:fast-math", "adder-codec-core/compression"]
open-cv = ["opencv", "davis-edi-rs"]
Expand All @@ -30,7 +30,6 @@ feature-logging-nonmaxsuppression = ["feature-logging"]


[dependencies]
packed_simd = "0.3.9"
bytemuck = "1.14.0"
adder-codec-core = { path = "../adder-codec-core", version = "0.3.2", default-features = false, optional = true}
#adder-codec-core = { version = "0.3.0", default-features = false, optional = true}
Expand All @@ -44,10 +43,13 @@ davis-edi-rs = { version = "0.2.4", optional = true }
duplicate = "0.4.1"
fast-math = { version = "0.1", optional = true }
fenwick = "2.0.1"
fixed = "1.25.1"
float-cmp = "0.9.0"
futures = "0.3.26"
generational-arena = "0.2"
itertools = "0.10.3"
kdtree = "0.7.0"
kiddo = "4.2.0"
ndarray = { version = "0.15.6", features = ["rayon", "serde"] }
num = "0.4"
num-traits = "0.2.15"
Expand Down
Loading

0 comments on commit 7520ab9

Please sign in to comment.