-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python package for data access in rust (#25)
* merging bioengineering code for ML pipelines (#24) * adding build using binary downloads (#8) * adding build using binary downloads * sorting out the build.rs * updating build.rs for surrealml package * prepping version for release * now has target tracking (#10) * adding check in build.rs for docs.rs * removing build.rs for main surrealml to ensure that libraries using the core do not need to do anything in their build.rs * Kings college london integration (#23) * adding machine learning pipelines for bioengineering projects at Kings College London * Remove integrated_training_runner/run_env/ from tracking * adding machine learning pipelines for bioengineering projects at Kings College London * adding python bindings to data access for ML training
- Loading branch information
1 parent
3a83a30
commit 4c490d4
Showing
18 changed files
with
132 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "data-access-layer" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
[lib] | ||
name = "data_access_layer" | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
|
||
[features] | ||
default = ["python"] | ||
python = ["pyo3"] | ||
|
||
|
||
[dependencies] | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
image = "0.24.8" | ||
# "abi3-py38" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.8 | ||
pyo3 = { version = "0.20.0", features = ["abi3-py38"], optional = true} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
[build-system] | ||
requires = ["maturin>=1.0,<2.0"] | ||
build-backend = "maturin" | ||
|
||
[tool.maturin] | ||
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so) | ||
features = ["pyo3/extension-module"] |
File renamed without changes.
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 @@ | ||
pub mod images; | ||
pub mod srt_reciever; | ||
pub mod tags; | ||
|
||
#[cfg(feature = "python")] | ||
pub mod python_api; | ||
|
||
#[cfg(feature = "python")] | ||
use pyo3::prelude::*; | ||
|
||
|
||
#[cfg(feature = "python")] | ||
#[pymodule] | ||
fn data_access_layer(_py: Python, m: &PyModule) -> PyResult<()> { | ||
m.add_function(wrap_pyfunction!(python_api::read_rgb_image, m)?)?; | ||
Ok(()) | ||
} | ||
|
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,13 @@ | ||
//! Here we define the Python API for data access layer. This is currently just one file, but we will probably | ||
//! expand this module into a directory with multiple files as the project grows as we will also need to define | ||
//! python classes in the future when building out the tags for the surgery steps. | ||
use crate::images::read_rgb_image as read_rgb_image_rust; | ||
|
||
use pyo3::prelude::*; | ||
|
||
|
||
#[pyfunction] | ||
pub fn read_rgb_image(path: String, width: usize, height: usize) -> PyResult<Vec<u8>> { | ||
let data = read_rgb_image_rust(path, width, height); | ||
Ok(data) | ||
} |
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
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
16 changes: 16 additions & 0 deletions
16
modules/pipelines/runners/integrated_training_runner/README.md
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,16 @@ | ||
# Integrated Runner | ||
|
||
This is where the image loading is still written in Rust, but there a python bindings meaning that the ML engineer | ||
can train the model in pure python importing and using the Rust code as a python library. This is done my merely | ||
pointing to the `data_access` library and performing a pip install. | ||
|
||
# Running the runner | ||
|
||
We can run the runner by running the following command: | ||
|
||
```bash | ||
sh ./scripts/run.sh | ||
``` | ||
|
||
This will import the Rust image loading code which will then load the image giving us the raw resized and flatterned | ||
image data in python. This can be directly fed into the ML model for training. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions
17
modules/pipelines/runners/integrated_training_runner/scripts/run.sh
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,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
# navigate to directory | ||
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" | ||
cd $SCRIPTPATH | ||
|
||
cd .. | ||
|
||
if [ -d run_env ]; then | ||
rm -rf run_env | ||
fi | ||
|
||
python3 -m venv run_env | ||
source run_env/bin/activate | ||
|
||
pip install ../../data_access | ||
python src/main.py |
12 changes: 12 additions & 0 deletions
12
modules/pipelines/runners/integrated_training_runner/src/main.py
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 @@ | ||
from data_access_layer.data_access_layer import read_rgb_image | ||
|
||
|
||
def main(): | ||
height = 480 | ||
width = 853 | ||
data = read_rgb_image("./assets/test.jpg", width, height) | ||
print(f"\n\nThe image has {len(data)} pixels\n\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |