Skip to content

Commit

Permalink
Merge pull request #13 from ianhi/multi-class
Browse files Browse the repository at this point in the history
Multi class + docs
  • Loading branch information
ianhi authored Oct 30, 2021
2 parents ee5c6c8 + 24043dd commit 05d702a
Show file tree
Hide file tree
Showing 25 changed files with 1,377 additions and 80 deletions.
12 changes: 12 additions & 0 deletions .binder/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# based on https://github.com/jupyterlab-contrib/jupyterlab-vim/blob/master/binder/environment.yml
name: mpl-image-labller-demo

channels:
- conda-forge

dependencies:
# runtime dependencies
- python >=3.8,<3.10.0a0
- jupyterlab >=3,<4.0.0a0
- pip
- ipympl
1 change: 1 addition & 0 deletions .binder/postBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python -m pip install -vvv -e .
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ repos:
rev: v0.812
hooks:
- id: mypy
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.1.1
hooks:
- id: nbqa-black
- id: nbqa-isort
- repo: https://github.com/kynan/nbstripout
rev: 0.5.0
hooks:
- id: nbstripout
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# mpl-image-labeller

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ianhi/mpl-image-labeller/main?urlpath=lab)
[![Documentation Status](https://readthedocs.org/projects/mpl-image-labeller/badge/?version=stable)](https://mpl-image-labeller.readthedocs.io/en/stable/?badge=stable)


[![License](https://img.shields.io/pypi/l/mpl-image-labeller.svg?color=green)](https://github.com/ianhi/mpl-image-labeller/raw/master/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/mpl-image-labeller.svg?color=green)](https://pypi.org/project/mpl-image-labeller)
[![Python Version](https://img.shields.io/pypi/pyversions/mpl-image-labeller.svg?color=green)](https://python.org)

Use Matplotlib to label images for classification. Works anywhere Matplotlib does - from the notebook to a standalone gui!

For more see the [documentation](https://mpl-image-labeller.readthedocs.io/en/stable/?badge=stable).

## Install

```bash
Expand All @@ -21,7 +27,13 @@ pip install mpl-image-labeller
- Smart interactions with default Matplotlib keymap
- Callback System (see `examples/callbacks.py`)

![gif of usage for labelling images of cats and dogs](example.gif)
**single class per image**

![gif of usage for labelling images of cats and dogs](docs/_static/single_class.gif)

**multiple classes per image**

![gif of usage for labelling images of cats and dogs](docs/_static/multi_class.gif)

## Usage

Expand Down
23 changes: 23 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?= -T --color
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

watch:
sphinx-autobuild . _build/html --open-browser --watch examples
22 changes: 22 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Fix numpydoc format delimiters */
.classifier:before {
font-style: normal;
margin: 0.5em;
content: ":";
}

/* override table no-wrap */
.wy-table-responsive table td,
.wy-table-responsive table th {
white-space: normal;
}

.text-align\:left, text-align\:left > p {
text-align: left
}
.text-align\:center, text-align\:center > p {
text-align: center
}
.text-align\:center, text-align\:right > p {
text-align: right
}
Binary file added docs/_static/multi_class.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/single_class.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions docs/api/mpl_image_labeller.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mpl\_image\_labeller package
============================

Module contents
---------------

.. automodule:: mpl_image_labeller
:members:
:undoc-members:
:show-inheritance:
228 changes: 228 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

import inspect

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import shutil
import subprocess
import sys

try:
from mpl_image_labeller import __version__ as release
except ImportError:
release = "unknown"


# -- Project information -----------------------------------------------------

project = "mpl-image-labeller"
copyright = "2021, Ian Hunt-Isaak"
author = "Ian Hunt-Isaak"


# -- Generate API ------------------------------------------------------------
api_folder_name = "api"
shutil.rmtree(api_folder_name, ignore_errors=True) # in case of new or renamed modules
subprocess.call(
" ".join(
[
"sphinx-apidoc",
f"-o {api_folder_name}/",
"--force",
"--no-toc",
"--templatedir _templates",
"--separate",
"../mpl_image_labeller/",
# excluded modules
# nothing here for cookiecutter
]
),
shell=True,
)


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"jupyter_sphinx",
"myst_nb",
"numpydoc",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.linkcode",
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"sphinx_copybutton",
"sphinx_panels",
"sphinx_thebe",
"sphinx_togglebutton",
]


# API settings
autodoc_default_options = {
"members": True,
"show-inheritance": True,
"undoc-members": True,
}
add_module_names = False
napoleon_google_docstring = False
napoleon_include_private_with_doc = False
napoleon_include_special_with_doc = False
napoleon_numpy_docstring = True
napoleon_use_admonition_for_examples = False
napoleon_use_admonition_for_notes = False
napoleon_use_admonition_for_references = False
napoleon_use_ivar = False
napoleon_use_param = False
napoleon_use_rtype = False
numpydoc_show_class_members = False

# Cross-referencing configuration
default_role = "py:obj"
primary_domain = "py"
nitpicky = True # warn if cross-references are missing

# Intersphinx settings
intersphinx_mapping = {
"ipywidgets": ("https://ipywidgets.readthedocs.io/en/stable", None),
"matplotlib": ("https://matplotlib.org/stable", None),
"numpy": ("https://numpy.org/doc/stable", None),
"python": ("https://docs.python.org/3", None),
}

# remove panels css to get wider main content
panels_add_bootstrap_css = False

# Settings for copybutton
copybutton_prompt_is_regexp = True
copybutton_prompt_text = r">>> |\.\.\. " # doctest

# Settings for linkcheck
linkcheck_anchors = False
linkcheck_ignore = [] # type: ignore

execution_timeout = -1
jupyter_execute_notebooks = "off"
if "EXECUTE_NB" in os.environ:
print("\033[93;1mWill run Jupyter notebooks!\033[0m")
jupyter_execute_notebooks = "force"

# Settings for myst-parser
myst_enable_extensions = [
"amsmath",
"colon_fence",
"dollarmath",
"smartquotes",
"substitution",
]
suppress_warnings = [
"myst.header",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
"**ipynb_checkpoints",
".DS_Store",
"Thumbs.db",
"_build",
]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_copy_source = True # needed for download notebook button
html_css_files = [
"custom.css",
]
html_sourcelink_suffix = ""
html_static_path = ["_static"]
html_theme = "sphinx_book_theme"
html_theme_options = {
"launch_buttons": {
"binderhub_url": "https://mybinder.org",
"colab_url": "https://colab.research.google.com",
"notebook_interface": "jupyterlab",
"thebe": True,
"thebelab": True,
},
"path_to_docs": "docs",
"repository_branch": "main",
"repository_url": "https://github.com/ianhi/mpl-image-labeller",
"use_download_button": True,
"use_edit_page_button": True,
"use_issues_button": True,
"use_repository_button": True,
}
html_title = "mpl-image-labeller"

master_doc = "index"
thebe_config = {
"repository_url": html_theme_options["repository_url"],
"repository_branch": html_theme_options["repository_branch"],
}


# based on pandas/doc/source/conf.py
def linkcode_resolve(domain, info):
"""
Determine the URL corresponding to Python object
"""
if domain != "py":
return None

modname = info["module"]
fullname = info["fullname"]

submod = sys.modules.get(modname)
if submod is None:
return None

obj = submod
for part in fullname.split("."):
try:
obj = getattr(obj, part)
except AttributeError:
return None

try:
fn = inspect.getsourcefile(inspect.unwrap(obj))
except TypeError:
fn = None
if not fn:
return None

try:
source, lineno = inspect.getsourcelines(obj)
except OSError:
lineno = None

if lineno:
linespec = f"#L{lineno}-L{lineno + len(source) - 1}"
else:
linespec = ""

fn = os.path.relpath(fn, start=os.path.dirname("../mpl_image_labeller"))

return f"https://github.com/ianhi/mpl-image-labeller/blob/main/mpl_image_labeller/{fn}{linespec}" # noqa
Loading

0 comments on commit 05d702a

Please sign in to comment.