Emb Deployment Package for Image Inference using Faster-RCNN and custom classification networks
Project description
embpred_deploy Documentation
Overview
embpred_deploy is a deployment package for running inference using Faster-RCNN and custom classification networks. It supports various input modes, including timelapse inference, single-image inference, and multi-focal depth inference.
Installation
1. Create and activate a Conda environment with Python 3.12
To ensure compatibility, create a new Conda environment:
conda create -n embd python=3.12
conda activate embd
2. Install embpred_deploy via pip
Standard Installation (with GPU support)
The default installation includes PyTorch with CUDA support:
pip install embpred_deploy
CPU-Only Installation (lighter weight)
For a lighter-weight CPU-only installation (recommended if you don't need GPU support):
# Install the package without PyTorch dependencies
pip install embpred_deploy --no-deps
# Install CPU-only PyTorch and torchvision
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
# Install remaining dependencies
pip install opencv-python-headless>=4.5.0 numpy>=1.21.0 matplotlib>=3.3.0 tqdm>=4.60.0
Or as a one-liner:
pip install embpred_deploy --no-deps && pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu && pip install opencv-python-headless numpy matplotlib tqdm
Note: The CPU-only installation is significantly smaller (~200MB vs ~2GB+) and is sufficient if you're running inference on CPU only.
Important: The PyPI package does not include model weights due to size limitations. You must download the model weights separately (see Model Weights Installation below).
3. Install embpred_deploy via Git
Alternatively, if you prefer to pull the latest code directly from GitHub, run:
git clone https://github.com/berkyalcinkaya/embpred_deploy.git
cd embpred_deploy
pip install -e .
Model Weights Installation
⚠️ REQUIRED: Pretrained model weights are not included in the PyPI package. You must download them separately to use the package.
Model weights are stored in a private AWS S3 bucket named cfai-model-weights. You will need AWS credentials with permission to read from this bucket (ask the project maintainer for access).
1. Install the AWS CLI (securely)
Follow the official AWS instructions for your platform (see the AWS CLI installation guide).
2. Authenticate with AWS
Configure your AWS credentials (access key, secret key, region) using:
aws configure
You can also use environment variables or an existing AWS profile; the important part is that the configured identity has s3:GetObject access to the cfai-model-weights bucket.
3. Download the model weights
First, find the models directory used by embpred_deploy:
python -c "from embpred_deploy.config import MODELS_DIR; print(MODELS_DIR)"
Then download the desired model into that directory. For the model
New-ResNet50-Unfreeze-CE-embSplits-overUnderSampleMedian-lessregularized-nodropout-3layer256,128,64.pth:
aws s3 cp \
"s3://cfai-model-weights/New-ResNet50-Unfreeze-CE-embSplits-overUnderSampleMedian-lessregularized-nodropout-3layer256,128,64.pth" \
/path/to/embpred_deploy/models/
Replace /path/to/embpred_deploy/models/ with the path printed by the MODELS_DIR command above.
Usage Instructions
To see all available CLI arguments and options, run:
embpred_deploy --help
If you are working from the source repository, you can also run:
python -m embpred_deploy.main --help
The inference script supports three main modes:
1. Timelapse Inference
Use the --timelapse-dir argument to process a sequence of images. This mode supports:
- Single image per timepoint: all images in one directory (each loaded in grayscale and duplicated to RGB).
- Multiple focal depths per timepoint: three subdirectories (each a focal depth); files are aligned by sorted filenames.
Example Command:
embpred_deploy \
--timelapse-dir /path/to/timelapse_data \
--model-name New-ResNet50-Unfreeze-CE-embSplits-overUnderSampleMedian-lessregularized-nodropout-3layer256,128,64 \
--postprocess
Key outputs:
- Raw outputs:
raw_timelapse_outputs.npy - If
--postprocessis enabled:max_prob_classes.csvmax_prob_classes.png
2. Single Image Inference
Use the --single-image argument to run inference on a single image. The image is processed by duplicating its grayscale channel into RGB.
Example Command:
embpred_deploy \
--single-image /path/to/image.jpg \
--model-name New-ResNet50-Unfreeze-CE-embSplits-overUnderSampleMedian-lessregularized-nodropout-3layer256,128,64
3. Three-Focal Depth Inference
Provide three separate focal depth images using the --F_neg15, --F0, and --F15 arguments.
Example Command:
embpred_deploy \
--F_neg15 /path/to/F_neg15.jpg \
--F0 /path/to/F0.jpg \
--F15 /path/to/F15.jpg \
--model-name New-ResNet50-Unfreeze-CE-embSplits-overUnderSampleMedian-lessregularized-nodropout-3layer256,128,64
Output Files
Mode 1: Timelapse (--timelapse-dir or --focal-depths)
This is the only mode that writes files. All files go into --output-dir (default = current working directory).
| File | Format | Shape | What it is |
|---|---|---|---|
raw_timelapse_outputs.npy |
NumPy binary | (T, 14) float |
The model's raw per-class scores at each timepoint t. Suitable for programmatic re-analysis. |
raw_timelapse_outputs.csv |
CSV with header | T+1 × 15 |
Same data as the .npy, but human-readable: header is timepoint,t1,tPN,tPNf,t2,…,tEmpty and each row is one timepoint's class scores. |
max_prob_classes.csv |
CSV with header | T+1 × 3 |
The predicted class per timepoint. Header: timepoint,class_index,class_name. With --postprocess, this is the monotonic-decoded sequence; without it, this is the per-timepoint raw argmax. |
max_prob_classes.png |
PNG plot | — | Line plot of class index over time. Y-axis is labeled with class names (t1, tPN, …, tEmpty); X-axis is timepoint index. |
postprocessed_timelapse_outputs.npy |
NumPy binary | (T,) int |
Only written with --postprocess. The monotonic-decoded class index at each timepoint. |
postprocessed_timelapse_outputs.csv |
CSV with header | T+1 × 3 |
Only written with --postprocess. Same data as the .npy, with timepoint,class_index,class_name columns. Effectively a copy of max_prob_classes.csv in this mode (kept separately so you always have the strict postprocessed sequence even if you change which sequence drives the plot). |
Assumptions & Notes
Input Image Format
- Single image inference:
- Image is loaded in grayscale and converted to 3-channel RGB.
- Timelapse mode:
- Image filenames must be sorted to ensure correct timepoint alignment.
Model Output
- Regular inference:
- The script maps raw model output to class labels.
- Timelapse inference:
- Raw probability vectors are returned unless
--postprocessis enabled.
- Raw probability vectors are returned unless
Dependencies
The package requires the following libraries (installed via pip or Conda):
pytorch(or CPU-only version for lighter install)torchvision(or CPU-only version for lighter install)opencv-python-headlessnumpymatplotlibtqdm
Note: For CPU-only installations, use the CPU-only versions of PyTorch and torchvision as described in the Installation section above. This significantly reduces the package size.
Ensure these dependencies are installed in your environment before running inference.
Development and Deployment
Setting up for Development
To set up the development environment:
# Clone the repository
git clone https://github.com/berkyalcinkaya/embpred_deploy.git
cd embpred_deploy
# Install development dependencies
pip install -r requirements-dev.txt
# Install the package in editable mode
pip install -e .
Deploying to PyPI
To deploy the package to PyPI:
-
Install deployment tools:
pip install -r requirements-dev.txt
-
Run the deployment script:
python build_and_deploy.py -
Or manually build and deploy:
# Clean previous builds rm -rf build/ dist/ *.egg-info/ # Build the package python -m build # Check the package python -m twine check dist/* # Upload to TestPyPI (recommended first) python -m twine upload --repository testpypi dist/* # Upload to PyPI (production) python -m twine upload dist/*
PyPI Credentials
You'll need to set up your PyPI credentials. Create a ~/.pypirc file:
[distutils]
index-servers =
pypi
testpypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = your_username
password = your_password
[testpypi]
repository = https://test.pypi.org/legacy/
username = your_username
password = your_password
Support
For further details or troubleshooting, please refer to the source code or contact the maintainers.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file embpred_deploy-1.1.2.tar.gz.
File metadata
- Download URL: embpred_deploy-1.1.2.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f92d1b15ad742a2dec9d249c9b019494a51a0147127a985ae8ffa8bdb3828863
|
|
| MD5 |
691ec3b552d06fc1dfe617784b916448
|
|
| BLAKE2b-256 |
dabfe288394cd650202deee41d2267dbd59982d0bc195b91f78f01ef2cf2c279
|
File details
Details for the file embpred_deploy-1.1.2-py3-none-any.whl.
File metadata
- Download URL: embpred_deploy-1.1.2-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17421eff5c16c2185f6eafaf988902b7a4113a8bded4bc5fefecfe6b227b8f14
|
|
| MD5 |
635cbeca4d4b33a2d55265847fc314cd
|
|
| BLAKE2b-256 |
617ebd42d62a100b2bd9436b998fcfaa88aed14309c3383732af87f83dda04af
|