Streamlit Image Annotation
Streamlit component for image annotation.
Features
- You can easily launch an image annotation tool using streamlit.
- By customizing the pre- and post-processing, you can achieve your preferred annotation workflow.
- Currently supports classification, detection, point detection tasks.
- Simple UI that is easy to navigate.
Install
pip install streamlit-image-annotation
Example Usage
If you want to see other use cases, please check inside the examples folder.
from glob import glob
import pandas as pd
import streamlit as st
from streamlit_image_annotation import classification
label_list = ['deer', 'human', 'dog', 'penguin', 'framingo', 'teddy bear']
image_path_list = glob('image/*.jpg')
if 'result_df' not in st.session_state:
st.session_state['result_df'] = pd.DataFrame.from_dict({'image': image_path_list, 'label': [0]*len(image_path_list)}).copy()
num_page = st.slider('page', 0, len(image_path_list)-1, 0)
label = classification(image_path_list[num_page],
label_list=label_list,
default_label_index=int(st.session_state['result_df'].loc[num_page, 'label']))
if label is not None and label['label'] != st.session_state['result_df'].loc[num_page, 'label']:
st.session_state['result_df'].loc[num_page, 'label'] = label_list.index(label['label'])
st.table(st.session_state['result_df'])
API
classification(
image_path: str,
label_list: List[str],
default_label_index: Optional[int] = None,
height: int = 512,
width: int = 512,
key: Optional[str] = None
)
-
image_path: Image path.
-
label_list: List of label candidates.
-
default_label_index: Initial label index.
-
height: The maximum height of the displayed image.
-
width: The maximum width of the displayed image.
-
key: An optional string to use as the unique key for the widget. Assign a key so the component is not remount every time the script is rerun.
-
Component Value: {'label': label_name}
Example: example code
detection(
image_path: str,
label_list: List[str],
bboxes: Optional[List[List[int, int, int, int]]] = None,
labels: Optional[List[int]] = None,
height: int = 512,
width: int = 512,
line_width: int = 5,
use_space: bool = False,
key: Optional[str] = None
)
-
image_path: Image path.
-
label_list: List of label candidates.
-
bboxes: Initial list of bounding boxes, where each bbox is in the format [x, y, w, h].
-
labels: List of label for each initial bbox.
-
height: The maximum height of the displayed image.
-
width: The maximum width of the displayed image.
-
line_width: The stroke width of the bbox.
-
use_space: Enable Space key for complete.
-
key: An optional string to use as the unique key for the widget. Assign a key so the component is not remount every time the script is rerun.
-
Component Value: [{'bbox':[x,y,width, height], 'label_id': label_id, 'label': label_name},...]
Example: example code
pointdet(
image_path: str,
label_list: List[str],
points: Optional[List[List[int, int]]] = None,
labels: Optional[List[int]] = None,
height: int = 512,
width: int = 512,
point_width: int =3,
use_space: bool = False,
key: Optional[str] = None
)
-
image_path: Image path.
-
label_list: List of label candidates.
-
points: Initial list of points, where each point is in the format [x, y].
-
labels: List of label for each initial bbox.
-
height: The maximum height of the displayed image.
-
width: The maximum width of the displayed image.
-
point_width: The stroke width of the bbox.
-
use_space: Enable Space key for complete.
-
key: An optional string to use as the unique key for the widget. Assign a key so the component is not remount every time the script is rerun.
-
Component Value: [{'bbox':[x,y], 'label_id': label_id, 'label': label_name},...]
Example: example code
Future Work
- Refactoring
- CI and Test
- Segmentation
Development
setup
cd Streamlit-Image-Annotation/
export PYTHONPATH=$PWD
and set IS_RELEASE = False in Streamlit-Image-Annotation/__init__.py.
start frontend
git clone https://github.com/hirune924/Streamlit-Image-Annotation.git
cd Streamlit-Image-Annotation/streamlit_image_annotation/Detection/frontend
yarn
yarn start
start streamlit
cd Streamlit-Image-Annotation/
streamlit run streamlit_image_annotation/Detection/__init__.py
build
You can use the automated build script to build all components and create the distribution package:
source .venv/bin/activate # Activate virtual environment first
./scripts/build_all.sh
This script will:
- Clean previous builds
- Build all three frontend components (Classification, Detection, Point)
- Create both wheel and source distribution packages in
dist/folder
The built package can be found in dist/streamlit_image_annotation-*.whl.
Alternatively, you can build manually:
cd Streamlit-Image-Annotation/Classification/frontend
yarn build
cd Streamlit-Image-Annotation/Detection/frontend
yarn build
cd Streamlit-Image-Annotation/Point/frontend
yarn build
and set IS_RELEASE = True in Streamlit-Image-Annotation/__init__.py.
Then create the wheel:
python setup.py sdist bdist_wheel
upload
python3 -m twine upload --repository testpypi dist/*
python -m pip install --index-url https://test.pypi.org/simple/ --no-deps streamlit-image-annotation
twine upload dist/*
Metadata
Release files for streamlit-image-annotation 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| streamlit_image_annotation-0.8.0.tar.gz | 3.2 MB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamlit_image_annotation-0.8.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.5 MB
Release files / streamlit_image_annotation-0.8.0.tar.gz
| Download URL | streamlit_image_annotation-0.8.0.tar.gz |
|---|---|
| Size | 3.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5d689b8d2a0330347ce4a1f1da4d118f0c14b30a1fbf21c5b392fbe0365274f0
|
|
BLAKE2b-256 checksum How to use checksums |
41de508dc123e998d94fd53bb99a3edeccff09990ccbd0718917982be97ab80a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.5
|
Release files / streamlit_image_annotation-0.8.0-py3-none-any.whl
| Download URL | streamlit_image_annotation-0.8.0-py3-none-any.whl |
|---|---|
| Size | 3.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bfc7c374365844aa00041f923bcc26282f3fa73b0195380aebececa349e8bc1
|
|
BLAKE2b-256 checksum How to use checksums |
22679fa70ab8385b219dee3314d039b26ac8d256a9dfb9514b530bc241af78d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.5
|
Security for streamlit-image-annotation 0.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.