Skip to main content

streamlit components for image annotation

Project description

Streamlit Image Annotation

Streamlit component for image annotation.

Streamlit App PyPI

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

  • Addition of component for segmentation task.

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

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.

make 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/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_image_annotation-0.4.0.tar.gz (3.2 MB view details)

Uploaded Source

Built Distribution

File details

Details for the file streamlit_image_annotation-0.4.0.tar.gz.

File metadata

File hashes

Hashes for streamlit_image_annotation-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e3ee66a5b405a0f5eec368dff9d94da7543067a36b142cd458ee7df8903ce093
MD5 508a8b0f5aebf9d08746fb582419f33f
BLAKE2b-256 89c82f4046b6280181c8c831f6f8b5ad0a7a06e3e4c18ca2d1843fa978519a48

See more details on using hashes here.

File details

Details for the file streamlit_image_annotation-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_image_annotation-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5506d5dfc53d0f9b889ebfc3f22434a715945142ddd17a301acbfd6d7f0a2b77
MD5 142cbc0cd2bf7357fbe88009da54cedf
BLAKE2b-256 0a1cd4b21372aff0371192d932e7d62cf7e03a78233d3296960e4aa875af4acd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page