Ver Fonte

code update

Tricolops há 10 meses atrás
pai
commit
7eeb4b7778
100 ficheiros alterados com 3992 adições e 0 exclusões
  1. 3 0
      .flake8
  2. 13 0
      .github/FUNDING.yml
  3. 45 0
      .github/ISSUE_TEMPLATE/1.bug_report.yml
  4. 10 0
      .github/ISSUE_TEMPLATE/config.yml
  5. 113 0
      .github/workflows/ci.yml
  6. 146 0
      .github/workflows/release.yml
  7. 11 0
      .gitignore
  8. 0 0
      .gitmodules
  9. 10 0
      CITATION.cff
  10. 15 0
      LICENSE
  11. 1 0
      MANIFEST.in
  12. 15 0
      Makefile
  13. 0 0
      REAME.md
  14. BIN
      examples/bbox_detection/.readme/annotation.jpg
  15. 25 0
      examples/bbox_detection/README.md
  16. BIN
      examples/bbox_detection/data_annotated/2011_000003.jpg
  17. 42 0
      examples/bbox_detection/data_annotated/2011_000003.json
  18. BIN
      examples/bbox_detection/data_annotated/2011_000006.jpg
  19. 74 0
      examples/bbox_detection/data_annotated/2011_000006.json
  20. BIN
      examples/bbox_detection/data_annotated/2011_000025.jpg
  21. 58 0
      examples/bbox_detection/data_annotated/2011_000025.json
  22. 37 0
      examples/bbox_detection/data_dataset_voc/Annotations/2011_000003.xml
  23. 61 0
      examples/bbox_detection/data_dataset_voc/Annotations/2011_000006.xml
  24. 49 0
      examples/bbox_detection/data_dataset_voc/Annotations/2011_000025.xml
  25. BIN
      examples/bbox_detection/data_dataset_voc/AnnotationsVisualization/2011_000003.jpg
  26. BIN
      examples/bbox_detection/data_dataset_voc/AnnotationsVisualization/2011_000006.jpg
  27. BIN
      examples/bbox_detection/data_dataset_voc/AnnotationsVisualization/2011_000025.jpg
  28. BIN
      examples/bbox_detection/data_dataset_voc/JPEGImages/2011_000003.jpg
  29. BIN
      examples/bbox_detection/data_dataset_voc/JPEGImages/2011_000006.jpg
  30. BIN
      examples/bbox_detection/data_dataset_voc/JPEGImages/2011_000025.jpg
  31. 21 0
      examples/bbox_detection/data_dataset_voc/class_names.txt
  32. 146 0
      examples/bbox_detection/labelme2voc.py
  33. 4 0
      examples/bbox_detection/labels.txt
  34. BIN
      examples/classification/.readme/annotation_cat.jpg
  35. BIN
      examples/classification/.readme/annotation_dog.jpg
  36. 11 0
      examples/classification/README.md
  37. BIN
      examples/classification/data_annotated/0001.jpg
  38. 13 0
      examples/classification/data_annotated/0001.json
  39. BIN
      examples/classification/data_annotated/0002.jpg
  40. 13 0
      examples/classification/data_annotated/0002.json
  41. 3 0
      examples/classification/flags.txt
  42. BIN
      examples/instance_segmentation/.readme/annotation.jpg
  43. BIN
      examples/instance_segmentation/.readme/draw_label_png_class.jpg
  44. BIN
      examples/instance_segmentation/.readme/draw_label_png_object.jpg
  45. 49 0
      examples/instance_segmentation/README.md
  46. BIN
      examples/instance_segmentation/data_annotated/2011_000003.jpg
  47. 478 0
      examples/instance_segmentation/data_annotated/2011_000003.json
  48. BIN
      examples/instance_segmentation/data_annotated/2011_000006.jpg
  49. 530 0
      examples/instance_segmentation/data_annotated/2011_000006.json
  50. BIN
      examples/instance_segmentation/data_annotated/2011_000025.jpg
  51. 210 0
      examples/instance_segmentation/data_annotated/2011_000025.json
  52. BIN
      examples/instance_segmentation/data_dataset_coco/JPEGImages/2011_000003.jpg
  53. BIN
      examples/instance_segmentation/data_dataset_coco/JPEGImages/2011_000006.jpg
  54. BIN
      examples/instance_segmentation/data_dataset_coco/JPEGImages/2011_000025.jpg
  55. BIN
      examples/instance_segmentation/data_dataset_coco/Visualization/2011_000003.jpg
  56. BIN
      examples/instance_segmentation/data_dataset_coco/Visualization/2011_000006.jpg
  57. BIN
      examples/instance_segmentation/data_dataset_coco/Visualization/2011_000025.jpg
  58. 0 0
      examples/instance_segmentation/data_dataset_coco/annotations.json
  59. BIN
      examples/instance_segmentation/data_dataset_voc/JPEGImages/2011_000003.jpg
  60. BIN
      examples/instance_segmentation/data_dataset_voc/JPEGImages/2011_000006.jpg
  61. BIN
      examples/instance_segmentation/data_dataset_voc/JPEGImages/2011_000025.jpg
  62. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationClass/2011_000003.png
  63. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationClass/2011_000006.png
  64. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationClass/2011_000025.png
  65. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationClassNpy/2011_000003.npy
  66. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationClassNpy/2011_000006.npy
  67. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationClassNpy/2011_000025.npy
  68. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationClassVisualization/2011_000003.jpg
  69. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationClassVisualization/2011_000006.jpg
  70. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationClassVisualization/2011_000025.jpg
  71. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationObject/2011_000003.png
  72. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationObject/2011_000006.png
  73. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationObject/2011_000025.png
  74. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationObjectNpy/2011_000003.npy
  75. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationObjectNpy/2011_000006.npy
  76. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationObjectNpy/2011_000025.npy
  77. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationObjectVisualization/2011_000003.jpg
  78. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationObjectVisualization/2011_000006.jpg
  79. BIN
      examples/instance_segmentation/data_dataset_voc/SegmentationObjectVisualization/2011_000025.jpg
  80. 21 0
      examples/instance_segmentation/data_dataset_voc/class_names.txt
  81. 203 0
      examples/instance_segmentation/labelme2coco.py
  82. 156 0
      examples/instance_segmentation/labelme2voc.py
  83. 22 0
      examples/instance_segmentation/labels.txt
  84. BIN
      examples/primitives/primitives.jpg
  85. 130 0
      examples/primitives/primitives.json
  86. BIN
      examples/semantic_segmentation/.readme/annotation.jpg
  87. BIN
      examples/semantic_segmentation/.readme/draw_label_png.jpg
  88. 36 0
      examples/semantic_segmentation/README.md
  89. BIN
      examples/semantic_segmentation/data_annotated/2011_000003.jpg
  90. 478 0
      examples/semantic_segmentation/data_annotated/2011_000003.json
  91. BIN
      examples/semantic_segmentation/data_annotated/2011_000006.jpg
  92. 530 0
      examples/semantic_segmentation/data_annotated/2011_000006.json
  93. BIN
      examples/semantic_segmentation/data_annotated/2011_000025.jpg
  94. 210 0
      examples/semantic_segmentation/data_annotated/2011_000025.json
  95. BIN
      examples/semantic_segmentation/data_dataset_voc/JPEGImages/2011_000003.jpg
  96. BIN
      examples/semantic_segmentation/data_dataset_voc/JPEGImages/2011_000006.jpg
  97. BIN
      examples/semantic_segmentation/data_dataset_voc/JPEGImages/2011_000025.jpg
  98. BIN
      examples/semantic_segmentation/data_dataset_voc/SegmentationClass/2011_000003.png
  99. BIN
      examples/semantic_segmentation/data_dataset_voc/SegmentationClass/2011_000006.png
  100. BIN
      examples/semantic_segmentation/data_dataset_voc/SegmentationClass/2011_000025.png

+ 3 - 0
.flake8

@@ -0,0 +1,3 @@
+[flake8]
+exclude = .*/
+ignore = E203, E741, W503, W504

+ 13 - 0
.github/FUNDING.yml

@@ -0,0 +1,13 @@
+# These are supported funding model platforms
+
+github: [wkentaro] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
+patreon: # Replace with a single Patreon username
+open_collective: # Replace with a single Open Collective username
+ko_fi: # Replace with a single Ko-fi username
+tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
+community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
+liberapay: # Replace with a single Liberapay username
+issuehunt: # Replace with a single IssueHunt username
+otechie: # Replace with a single Otechie username
+lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
+custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

+ 45 - 0
.github/ISSUE_TEMPLATE/1.bug_report.yml

@@ -0,0 +1,45 @@
+name: Bug Report
+description: Create a bug report
+labels: 'bug'
+body:
+  - type: markdown
+    attributes:
+      value: Thanks for taking the time to file a bug report! Please fill out this form as completely as possible.
+  - type: markdown
+    attributes:
+      value: If you leave out sections there is a high likelihood it will be moved to the GitHub Discussions ["Q&A / Help" section](https://github.com/wkentaro/labelme/discussions/categories/q-a-help).
+  - type: textarea
+    attributes:
+      label: Provide environment information
+      description: Please run `which python; python --version; python -m pip list | grep labelme` in the root directory of your project and paste the results.
+    validations:
+      required: true
+  - type: input
+    attributes:
+      label: What OS are you using?
+      description: 'Please specify the exact version. For example: macOS 12.4, Ubuntu 20.04.4'
+    validations:
+      required: true
+  - type: textarea
+    attributes:
+      label: Describe the Bug
+      description: A clear and concise description of what the bug is.
+    validations:
+      required: true
+  - type: textarea
+    attributes:
+      label: Expected Behavior
+      description: A clear and concise description of what you expected to happen.
+  - type: textarea
+    attributes:
+      label: To Reproduce
+      description: Steps to reproduce the behavior, please provide a clear description of how to reproduce the issue, based on the linked minimal reproduction. Screenshots can be provided in the issue body below. If using code blocks, make sure that [syntax highlighting is correct](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting) and double check that the rendered preview is not broken.
+  - type: markdown
+    attributes:
+      value: Before posting the issue go through the steps you've written down to make sure the steps provided are detailed and clear.
+  - type: markdown
+    attributes:
+      value: Contributors should be able to follow the steps provided in order to reproduce the bug.
+  - type: markdown
+    attributes:
+      value: These steps are used to add integration tests to ensure the same issue does not happen again. Thanks in advance!

+ 10 - 0
.github/ISSUE_TEMPLATE/config.yml

@@ -0,0 +1,10 @@
+contact_links:
+  - name: Ideas / Feature request
+    url: https://github.com/wkentaro/labelme/discussions/categories/ideas-feature-requests
+    about: Share ideas for new features
+  - name: Q&A / Help
+    url: https://github.com/wkentaro/labelme/discussions/categories/q-a-help
+    about: Ask the community for help
+  - name: Show and tell
+    url: https://github.com/wkentaro/labelme/discussions/categories/show-and-tell
+    about: Show off something you've made

+ 113 - 0
.github/workflows/ci.yml

@@ -0,0 +1,113 @@
+name: ci
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+
+jobs:
+  build:
+
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [macos-latest, ubuntu-latest, windows-latest]
+        python-version: ['3.9']
+        PYTEST_QT_API: [pyqt5, pyside2]
+
+    steps:
+    - uses: actions/checkout@v2
+      with:
+        submodules: true
+
+    - uses: conda-incubator/setup-miniconda@v3
+      with:
+        auto-update-conda: true
+        python-version: ${{ matrix.python-version }}
+
+    # - name: Install system dependencies
+    #   shell: bash -l {0}
+    #   run: |
+    #     if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
+    #       sudo apt-get install -y coreutils
+    #       sudo apt-get install -y xvfb herbstluftwm
+    #     elif [ "${{ matrix.os }}" = "macos-latest" ]; then
+    #       brew install coreutils
+    #       brew install --cask xquartz
+    #     fi
+
+    - name: Set up Python
+      shell: bash -l {0}
+      run: |
+        conda install -q -y python=${{ matrix.python-version }}
+        which python
+        python --version
+        pip --version
+
+    - name: Install dependencies
+      shell: bash -l {0}
+      run: |
+        if [ "${{ matrix.PYTEST_QT_API }}" = "pyside2" ]; then
+          conda install -q -y pyside2 -c conda-forge
+        # should be installed via pip
+        # else
+        #   conda install -q -y pyqt=5
+        fi
+        pip install -r requirements-dev.txt
+
+    - name: Install main
+      shell: bash -l {0}
+      run: |
+        pip install .
+
+    - name: Run ruff
+      shell: bash -l {0}
+      if: matrix.os != 'windows-latest'
+      run: |
+        ruff format --check
+        ruff check
+
+    - name: Test with pytest
+      shell: bash -l {0}
+      if: matrix.os == 'ubuntu-latest'
+      env:
+        PYTEST_QT_API: ${{ matrix.PYTEST_QT_API }}
+        MPLBACKEND: 'agg'
+      run: |
+        sudo apt-get update
+        sudo apt-get install -y xvfb libqt5widgets5
+
+        Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
+        export DISPLAY=:99
+
+        pytest tests
+
+    - name: Run examples
+      shell: bash -l {0}
+      if: matrix.os != 'windows-latest'
+      env:
+        MPLBACKEND: agg
+      run: |
+        labelme --help
+        labelme --version
+        (cd examples/primitives && labelme_json_to_dataset primitives.json && rm -rf primitives_json)
+        (cd examples/tutorial && rm -rf apc2016_obj3_json && labelme_json_to_dataset apc2016_obj3.json && python load_label_png.py && git checkout -- .)
+        (cd examples/semantic_segmentation && rm -rf data_dataset_voc && ./labelme2voc.py data_annotated data_dataset_voc --labels labels.txt && git checkout -- .)
+        (cd examples/instance_segmentation && rm -rf data_dataset_voc && ./labelme2voc.py data_annotated data_dataset_voc --labels labels.txt && git checkout -- .)
+        (cd examples/video_annotation && rm -rf data_dataset_voc && ./labelme2voc.py data_annotated data_dataset_voc --labels labels.txt && git checkout -- .)
+
+        pip install 'lxml<5.0.0'  # for bbox_detection/labelme2voc.py
+        (cd examples/bbox_detection && rm -rf data_dataset_voc && ./labelme2voc.py data_annotated data_dataset_voc --labels labels.txt && git checkout -- .)
+
+        pip install cython && pip install pycocotools  # for instance_segmentation/labelme2coco.py
+        (cd examples/instance_segmentation && rm -rf data_dataset_coco && ./labelme2coco.py data_annotated data_dataset_coco --labels labels.txt && git checkout -- .)
+
+    - name: Run pyinstaller
+      shell: bash -l {0}
+      if: matrix.PYTEST_QT_API == 'pyqt5'
+      run: |
+        # Build the standalone executable
+        pip install pyinstaller
+        pyinstaller labelme.spec
+        dist/labelme --version

+ 146 - 0
.github/workflows/release.yml

@@ -0,0 +1,146 @@
+name: release
+
+on:
+  push:
+    tags:
+    - 'v*'
+
+permissions:
+  contents: write
+
+jobs:
+  release:
+    if: startsWith(github.ref, 'refs/tags/')
+
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Build Changelog
+        id: github_release
+        uses: mikepenz/release-changelog-builder-action@v3
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        with:
+          configurationJson: |
+            {
+                "template": "#{{CHANGELOG}}\n\n<details>\n<summary>",
+                "pr_template": "- #{{TITLE}} ##{{NUMBER}} (Thanks @#{{AUTHOR}})",
+                "categories": [
+                    {
+                        "title": "## 🚀 Features",
+                        "labels": ["feature"]
+                    },
+                    {
+                        "title": "## ✨ Enhancement",
+                        "labels": ["enhancement"]
+                    },
+                    {
+                        "title": "## 🐛 Fixes",
+                        "labels": ["fix"]
+                    },
+                    {
+                        "title": "## 💬 Other",
+                        "labels": ["other"]
+                    }
+                ]
+            }
+
+      - name: Create Release
+        id: create_release
+        uses: mikepenz/action-gh-release@v0.2.0-a03
+        with:
+          body: ${{steps.github_release.outputs.changelog}}
+          draft: true
+
+      - name: Create release url file
+        run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt
+
+      - name: Save release url file for publish
+        uses: actions/upload-artifact@v1
+        with:
+          name: release_url
+          path: release_url.txt
+
+  publish:
+    needs: [release]
+
+    strategy:
+      matrix:
+        os: [macos-latest, ubuntu-latest, windows-latest]
+
+    runs-on: ${{ matrix.os }}
+
+    steps:
+    - uses: actions/checkout@v2
+      with:
+        submodules: true
+
+    - uses: conda-incubator/setup-miniconda@v3
+      with:
+        auto-update-conda: true
+        python-version: '3.9'
+
+    - name: Install main
+      shell: bash -l {0}
+      run: |
+        pip install .
+
+    - name: Run pyinstaller
+      shell: bash -l {0}
+      run: |
+        pip install pyinstaller
+        pyinstaller labelme.spec
+
+    - name: Load release url file from release job
+      uses: actions/download-artifact@v1
+      with:
+        name: release_url
+
+    - name: Get release file name & upload url
+      id: get_release_info
+      run: |
+        echo "::set-output name=upload_url::$(cat release_url/release_url.txt)"
+
+    - name: Upload release executable on macOS & Linux
+      id: upload_release_executable_macos_linux
+      uses: actions/upload-release-asset@v1
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      with:
+        upload_url: ${{ steps.get_release_info.outputs.upload_url }}
+        asset_path: ./dist/labelme
+        asset_name: labelme-${{ runner.os }}
+        asset_content_type: application/octet-stream
+      if: runner.os != 'Windows'
+
+    - name: Upload release executable on Windows
+      id: upload_release_executable_windows
+      uses: actions/upload-release-asset@v1
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      with:
+        upload_url: ${{ steps.get_release_info.outputs.upload_url }}
+        asset_path: ./dist/labelme.exe
+        asset_name: Labelme.exe
+        asset_content_type: application/octet-stream
+      if: runner.os == 'Windows'
+
+    - name: Create dmg for macOS
+      run: |
+        npm install -g create-dmg
+        cd dist
+        create-dmg Labelme.app || test -f Labelme\ 0.0.0.dmg
+        mv Labelme\ 0.0.0.dmg Labelme.dmg
+      if: runner.os == 'macOS'
+
+    - name: Upload release app on macOS
+      id: upload_release_app_macos
+      uses: actions/upload-release-asset@v1
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      with:
+        upload_url: ${{ steps.get_release_info.outputs.upload_url }}
+        asset_path: ./dist/Labelme.dmg
+        asset_name: Labelme.dmg
+        asset_content_type: application/octet-stream
+      if: runner.os == 'macOS'

+ 11 - 0
.gitignore

@@ -0,0 +1,11 @@
+/.cache/
+/.pytest_cache/
+
+/build/
+/dist/
+/*.egg-info/
+
+*.py[cdo]
+
+.DS_Store
+.idea/

+ 0 - 0
.gitmodules


+ 10 - 0
CITATION.cff

@@ -0,0 +1,10 @@
+cff-version: 1.2.0
+message: "If you use this software, please cite it as below."
+authors:
+- family-names: "Wada"
+  given-names: "Kentaro"
+  orcid: "https://orcid.org/0000-0002-6347-5156"
+title: "Labelme: Image Polygonal Annotation with Python"
+doi: 10.5281/zenodo.5711226
+url: "https://github.com/wkentaro/labelme"
+license: GPL-3

+ 15 - 0
LICENSE

@@ -0,0 +1,15 @@
+Copyright (C) 2016 Kentaro Wada.
+Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
+
+Labelme is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Labelme is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Labelme.  If not, see <http://www.gnu.org/licenses/>.

+ 1 - 0
MANIFEST.in

@@ -0,0 +1 @@
+include README.md

+ 15 - 0
Makefile

@@ -0,0 +1,15 @@
+all:
+	@echo '## Make commands ##'
+	@echo
+	@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
+
+lint:
+	ruff format --check
+	ruff check
+
+format:
+	ruff format
+	ruff check --fix
+
+test:
+	MPLBACKEND='agg' pytest tests

+ 0 - 0
REAME.md


BIN
examples/bbox_detection/.readme/annotation.jpg


+ 25 - 0
examples/bbox_detection/README.md

@@ -0,0 +1,25 @@
+# Bounding Box Detection Example
+
+
+## Usage
+
+```bash
+labelme data_annotated --labels labels.txt --nodata --autosave
+```
+
+![](.readme/annotation.jpg)
+
+
+## Convert to VOC-format Dataset
+
+```bash
+# It generates:
+#   - data_dataset_voc/JPEGImages
+#   - data_dataset_voc/Annotations
+#   - data_dataset_voc/AnnotationsVisualization
+./labelme2voc.py data_annotated data_dataset_voc --labels labels.txt
+```
+
+<img src="data_dataset_voc/JPEGImages/2011_000003.jpg" width="33%" /> <img src="data_dataset_voc/AnnotationsVisualization/2011_000003.jpg" width="33%" />
+
+<i>Fig1. JPEG image (left), Bounding box annotation visualization (right).</i>

BIN
examples/bbox_detection/data_annotated/2011_000003.jpg


+ 42 - 0
examples/bbox_detection/data_annotated/2011_000003.json

@@ -0,0 +1,42 @@
+{
+  "version": "4.0.0",
+  "flags": {},
+  "shapes": [
+    {
+      "label": "person",
+      "points": [
+        [
+          191.0,
+          107.36900369003689
+        ],
+        [
+          313.0,
+          329.36900369003695
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          365.0,
+          83.0
+        ],
+        [
+          500.0,
+          333.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    }
+  ],
+  "imagePath": "2011_000003.jpg",
+  "imageData": null,
+  "imageHeight": 338,
+  "imageWidth": 500
+}

BIN
examples/bbox_detection/data_annotated/2011_000006.jpg


+ 74 - 0
examples/bbox_detection/data_annotated/2011_000006.json

@@ -0,0 +1,74 @@
+{
+  "version": "4.0.0",
+  "flags": {},
+  "shapes": [
+    {
+      "label": "person",
+      "points": [
+        [
+          91.0,
+          107.0
+        ],
+        [
+          240.0,
+          330.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          178.0,
+          110.0
+        ],
+        [
+          298.0,
+          282.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          254.38461538461536,
+          115.38461538461539
+        ],
+        [
+          369.38461538461536,
+          292.38461538461536
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          395.0,
+          81.0
+        ],
+        [
+          447.0,
+          117.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    }
+  ],
+  "imagePath": "2011_000006.jpg",
+  "imageData": null,
+  "imageHeight": 375,
+  "imageWidth": 500
+}

BIN
examples/bbox_detection/data_annotated/2011_000025.jpg


+ 58 - 0
examples/bbox_detection/data_annotated/2011_000025.json

@@ -0,0 +1,58 @@
+{
+  "version": "4.0.0",
+  "flags": {},
+  "shapes": [
+    {
+      "label": "bus",
+      "points": [
+        [
+          84.0,
+          20.384615384615387
+        ],
+        [
+          435.0,
+          373.38461538461536
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    },
+    {
+      "label": "bus",
+      "points": [
+        [
+          1.0,
+          99.0
+        ],
+        [
+          107.0,
+          282.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    },
+    {
+      "label": "car",
+      "points": [
+        [
+          409.0,
+          167.0
+        ],
+        [
+          500.0,
+          266.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    }
+  ],
+  "imagePath": "2011_000025.jpg",
+  "imageData": null,
+  "imageHeight": 375,
+  "imageWidth": 500
+}

+ 37 - 0
examples/bbox_detection/data_dataset_voc/Annotations/2011_000003.xml

@@ -0,0 +1,37 @@
+<annotation>
+  <folder/>
+  <filename>2011_000003.jpg</filename>
+  <database/>
+  <annotation/>
+  <image/>
+  <size>
+    <height>338</height>
+    <width>500</width>
+    <depth>3</depth>
+  </size>
+  <segmented/>
+  <object>
+    <name>person</name>
+    <pose/>
+    <truncated/>
+    <difficult/>
+    <bndbox>
+      <xmin>191.0</xmin>
+      <ymin>107.36900369003689</ymin>
+      <xmax>313.0</xmax>
+      <ymax>329.36900369003695</ymax>
+    </bndbox>
+  </object>
+  <object>
+    <name>person</name>
+    <pose/>
+    <truncated/>
+    <difficult/>
+    <bndbox>
+      <xmin>365.0</xmin>
+      <ymin>83.0</ymin>
+      <xmax>500.0</xmax>
+      <ymax>333.0</ymax>
+    </bndbox>
+  </object>
+</annotation>

+ 61 - 0
examples/bbox_detection/data_dataset_voc/Annotations/2011_000006.xml

@@ -0,0 +1,61 @@
+<annotation>
+  <folder/>
+  <filename>2011_000006.jpg</filename>
+  <database/>
+  <annotation/>
+  <image/>
+  <size>
+    <height>375</height>
+    <width>500</width>
+    <depth>3</depth>
+  </size>
+  <segmented/>
+  <object>
+    <name>person</name>
+    <pose/>
+    <truncated/>
+    <difficult/>
+    <bndbox>
+      <xmin>91.0</xmin>
+      <ymin>107.0</ymin>
+      <xmax>240.0</xmax>
+      <ymax>330.0</ymax>
+    </bndbox>
+  </object>
+  <object>
+    <name>person</name>
+    <pose/>
+    <truncated/>
+    <difficult/>
+    <bndbox>
+      <xmin>178.0</xmin>
+      <ymin>110.0</ymin>
+      <xmax>298.0</xmax>
+      <ymax>282.0</ymax>
+    </bndbox>
+  </object>
+  <object>
+    <name>person</name>
+    <pose/>
+    <truncated/>
+    <difficult/>
+    <bndbox>
+      <xmin>254.38461538461536</xmin>
+      <ymin>115.38461538461539</ymin>
+      <xmax>369.38461538461536</xmax>
+      <ymax>292.38461538461536</ymax>
+    </bndbox>
+  </object>
+  <object>
+    <name>person</name>
+    <pose/>
+    <truncated/>
+    <difficult/>
+    <bndbox>
+      <xmin>395.0</xmin>
+      <ymin>81.0</ymin>
+      <xmax>447.0</xmax>
+      <ymax>117.0</ymax>
+    </bndbox>
+  </object>
+</annotation>

+ 49 - 0
examples/bbox_detection/data_dataset_voc/Annotations/2011_000025.xml

@@ -0,0 +1,49 @@
+<annotation>
+  <folder/>
+  <filename>2011_000025.jpg</filename>
+  <database/>
+  <annotation/>
+  <image/>
+  <size>
+    <height>375</height>
+    <width>500</width>
+    <depth>3</depth>
+  </size>
+  <segmented/>
+  <object>
+    <name>bus</name>
+    <pose/>
+    <truncated/>
+    <difficult/>
+    <bndbox>
+      <xmin>84.0</xmin>
+      <ymin>20.384615384615387</ymin>
+      <xmax>435.0</xmax>
+      <ymax>373.38461538461536</ymax>
+    </bndbox>
+  </object>
+  <object>
+    <name>bus</name>
+    <pose/>
+    <truncated/>
+    <difficult/>
+    <bndbox>
+      <xmin>1.0</xmin>
+      <ymin>99.0</ymin>
+      <xmax>107.0</xmax>
+      <ymax>282.0</ymax>
+    </bndbox>
+  </object>
+  <object>
+    <name>car</name>
+    <pose/>
+    <truncated/>
+    <difficult/>
+    <bndbox>
+      <xmin>409.0</xmin>
+      <ymin>167.0</ymin>
+      <xmax>500.0</xmax>
+      <ymax>266.0</ymax>
+    </bndbox>
+  </object>
+</annotation>

BIN
examples/bbox_detection/data_dataset_voc/AnnotationsVisualization/2011_000003.jpg


BIN
examples/bbox_detection/data_dataset_voc/AnnotationsVisualization/2011_000006.jpg


BIN
examples/bbox_detection/data_dataset_voc/AnnotationsVisualization/2011_000025.jpg


BIN
examples/bbox_detection/data_dataset_voc/JPEGImages/2011_000003.jpg


BIN
examples/bbox_detection/data_dataset_voc/JPEGImages/2011_000006.jpg


BIN
examples/bbox_detection/data_dataset_voc/JPEGImages/2011_000025.jpg


+ 21 - 0
examples/bbox_detection/data_dataset_voc/class_names.txt

@@ -0,0 +1,21 @@
+_background_
+aeroplane
+bicycle
+bird
+boat
+bottle
+bus
+car
+cat
+chair
+cow
+diningtable
+dog
+horse
+motorbike
+person
+potted plant
+sheep
+sofa
+train
+tv/monitor

+ 146 - 0
examples/bbox_detection/labelme2voc.py

@@ -0,0 +1,146 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+
+import argparse
+import glob
+import os
+import os.path as osp
+import sys
+
+import imgviz
+
+import labelme
+
+try:
+    import lxml.builder
+    import lxml.etree
+except ImportError:
+    print("Please install lxml:\n\n    pip install lxml\n")
+    sys.exit(1)
+
+
+def main():
+    parser = argparse.ArgumentParser(
+        formatter_class=argparse.ArgumentDefaultsHelpFormatter
+    )
+    parser.add_argument("input_dir", help="input annotated directory")
+    parser.add_argument("output_dir", help="output dataset directory")
+    parser.add_argument("--labels", help="labels file", required=True)
+    parser.add_argument("--noviz", help="no visualization", action="store_true")
+    args = parser.parse_args()
+
+    if osp.exists(args.output_dir):
+        print("Output directory already exists:", args.output_dir)
+        sys.exit(1)
+    os.makedirs(args.output_dir)
+    os.makedirs(osp.join(args.output_dir, "JPEGImages"))
+    os.makedirs(osp.join(args.output_dir, "Annotations"))
+    if not args.noviz:
+        os.makedirs(osp.join(args.output_dir, "AnnotationsVisualization"))
+    print("Creating dataset:", args.output_dir)
+
+    class_names = []
+    class_name_to_id = {}
+    for i, line in enumerate(open(args.labels).readlines()):
+        class_id = i - 1  # starts with -1
+        class_name = line.strip()
+        class_name_to_id[class_name] = class_id
+        if class_id == -1:
+            assert class_name == "__ignore__"
+            continue
+        elif class_id == 0:
+            assert class_name == "_background_"
+        class_names.append(class_name)
+    class_names = tuple(class_names)
+    print("class_names:", class_names)
+    out_class_names_file = osp.join(args.output_dir, "class_names.txt")
+    with open(out_class_names_file, "w") as f:
+        f.writelines("\n".join(class_names))
+    print("Saved class_names:", out_class_names_file)
+
+    for filename in glob.glob(osp.join(args.input_dir, "*.json")):
+        print("Generating dataset from:", filename)
+
+        label_file = labelme.LabelFile(filename=filename)
+
+        base = osp.splitext(osp.basename(filename))[0]
+        out_img_file = osp.join(args.output_dir, "JPEGImages", base + ".jpg")
+        out_xml_file = osp.join(args.output_dir, "Annotations", base + ".xml")
+        if not args.noviz:
+            out_viz_file = osp.join(
+                args.output_dir, "AnnotationsVisualization", base + ".jpg"
+            )
+
+        img = labelme.utils.img_data_to_arr(label_file.imageData)
+        imgviz.io.imsave(out_img_file, img)
+
+        maker = lxml.builder.ElementMaker()
+        xml = maker.annotation(
+            maker.folder(),
+            maker.filename(base + ".jpg"),
+            maker.database(),  # e.g., The VOC2007 Database
+            maker.annotation(),  # e.g., Pascal VOC2007
+            maker.image(),  # e.g., flickr
+            maker.size(
+                maker.height(str(img.shape[0])),
+                maker.width(str(img.shape[1])),
+                maker.depth(str(img.shape[2])),
+            ),
+            maker.segmented(),
+        )
+
+        bboxes = []
+        labels = []
+        for shape in label_file.shapes:
+            if shape["shape_type"] != "rectangle":
+                print(
+                    "Skipping shape: label={label}, " "shape_type={shape_type}".format(
+                        **shape
+                    )
+                )
+                continue
+
+            class_name = shape["label"]
+            class_id = class_names.index(class_name)
+
+            (xmin, ymin), (xmax, ymax) = shape["points"]
+            # swap if min is larger than max.
+            xmin, xmax = sorted([xmin, xmax])
+            ymin, ymax = sorted([ymin, ymax])
+
+            bboxes.append([ymin, xmin, ymax, xmax])
+            labels.append(class_id)
+
+            xml.append(
+                maker.object(
+                    maker.name(shape["label"]),
+                    maker.pose(),
+                    maker.truncated(),
+                    maker.difficult(),
+                    maker.bndbox(
+                        maker.xmin(str(xmin)),
+                        maker.ymin(str(ymin)),
+                        maker.xmax(str(xmax)),
+                        maker.ymax(str(ymax)),
+                    ),
+                )
+            )
+
+        if not args.noviz:
+            captions = [class_names[label] for label in labels]
+            viz = imgviz.instances2rgb(
+                image=img,
+                labels=labels,
+                bboxes=bboxes,
+                captions=captions,
+                font_size=15,
+            )
+            imgviz.io.imsave(out_viz_file, viz)
+
+        with open(out_xml_file, "wb") as f:
+            f.write(lxml.etree.tostring(xml, pretty_print=True))
+
+
+if __name__ == "__main__":
+    main()

+ 4 - 0
examples/bbox_detection/labels.txt

@@ -0,0 +1,4 @@
+__ignore__
+_background_
+barcode
+tough_barcode

BIN
examples/classification/.readme/annotation_cat.jpg


BIN
examples/classification/.readme/annotation_dog.jpg


+ 11 - 0
examples/classification/README.md

@@ -0,0 +1,11 @@
+# Classification Example
+
+
+## Usage
+
+```bash
+labelme data_annotated --flags flags.txt --nodata
+```
+
+<img src=".readme/annotation_cat.jpg" width="100%" />
+<img src=".readme/annotation_dog.jpg" width="100%" />

BIN
examples/classification/data_annotated/0001.jpg


+ 13 - 0
examples/classification/data_annotated/0001.json

@@ -0,0 +1,13 @@
+{
+  "version": "4.0.0",
+  "flags": {
+    "__ignore__": false,
+    "cat": true,
+    "dog": false
+  },
+  "shapes": [],
+  "imagePath": "0001.jpg",
+  "imageData": null,
+  "imageHeight": 480,
+  "imageWidth": 640
+}

BIN
examples/classification/data_annotated/0002.jpg


+ 13 - 0
examples/classification/data_annotated/0002.json

@@ -0,0 +1,13 @@
+{
+  "version": "4.0.0",
+  "flags": {
+    "__ignore__": false,
+    "cat": false,
+    "dog": true
+  },
+  "shapes": [],
+  "imagePath": "0002.jpg",
+  "imageData": null,
+  "imageHeight": 480,
+  "imageWidth": 640
+}

+ 3 - 0
examples/classification/flags.txt

@@ -0,0 +1,3 @@
+__ignore__
+cat
+dog

BIN
examples/instance_segmentation/.readme/annotation.jpg


BIN
examples/instance_segmentation/.readme/draw_label_png_class.jpg


BIN
examples/instance_segmentation/.readme/draw_label_png_object.jpg


+ 49 - 0
examples/instance_segmentation/README.md

@@ -0,0 +1,49 @@
+# Instance Segmentation Example
+
+## Annotation
+
+```bash
+labelme data_annotated --labels labels.txt --nodata --validatelabel exact --config '{shift_auto_shape_color: -2}'
+labelme data_annotated --labels labels.txt --nodata --labelflags '{.*: [occluded, truncated], person: [male]}'
+```
+
+![](.readme/annotation.jpg)
+
+## Convert to VOC-format Dataset
+
+```bash
+# It generates:
+#   - data_dataset_voc/JPEGImages
+#   - data_dataset_voc/SegmentationClass
+#   - data_dataset_voc/SegmentationClassNpy
+#   - data_dataset_voc/SegmentationClassVisualization
+#   - data_dataset_voc/SegmentationObject
+#   - data_dataset_voc/SegmentationObjectNpy
+#   - data_dataset_voc/SegmentationObjectVisualization
+./labelme2voc.py data_annotated data_dataset_voc --labels labels.txt
+```
+
+<img src="data_dataset_voc/JPEGImages/2011_000003.jpg" width="33%" /> <img src="data_dataset_voc/SegmentationClassVisualization/2011_000003.jpg" width="33%" /> <img src="data_dataset_voc/SegmentationObjectVisualization/2011_000003.jpg" width="33%" />  
+Fig 1. JPEG image (left), JPEG class label visualization (center), JPEG instance label visualization (right)
+
+
+Note that the label file contains only very low label values (ex. `0, 4, 14`), and
+`255` indicates the `__ignore__` label value (`-1` in the npy file).  
+You can see the label PNG file by following.
+
+```bash
+labelme_draw_label_png data_dataset_voc/SegmentationClass/2011_000003.png   # left
+labelme_draw_label_png data_dataset_voc/SegmentationObject/2011_000003.png  # right
+```
+
+<img src=".readme/draw_label_png_class.jpg" width="33%" /> <img src=".readme/draw_label_png_object.jpg" width="33%" />
+
+
+## Convert to COCO-format Dataset
+
+```bash
+# It generates:
+#   - data_dataset_coco/JPEGImages
+#   - data_dataset_coco/annotations.json
+./labelme2coco.py data_annotated data_dataset_coco --labels labels.txt
+```

BIN
examples/instance_segmentation/data_annotated/2011_000003.jpg


+ 478 - 0
examples/instance_segmentation/data_annotated/2011_000003.json

@@ -0,0 +1,478 @@
+{
+  "version": "4.0.0",
+  "flags": {},
+  "shapes": [
+    {
+      "label": "person",
+      "points": [
+        [
+          250.8142292490119,
+          107.33596837944665
+        ],
+        [
+          229.8142292490119,
+          119.33596837944665
+        ],
+        [
+          221.8142292490119,
+          135.33596837944665
+        ],
+        [
+          223.8142292490119,
+          148.33596837944665
+        ],
+        [
+          217.8142292490119,
+          161.33596837944665
+        ],
+        [
+          202.8142292490119,
+          168.33596837944665
+        ],
+        [
+          192.8142292490119,
+          200.33596837944665
+        ],
+        [
+          194.8142292490119,
+          222.33596837944665
+        ],
+        [
+          199.8142292490119,
+          227.33596837944665
+        ],
+        [
+          191.8142292490119,
+          234.33596837944665
+        ],
+        [
+          197.8142292490119,
+          264.3359683794467
+        ],
+        [
+          213.8142292490119,
+          295.3359683794467
+        ],
+        [
+          214.8142292490119,
+          320.3359683794467
+        ],
+        [
+          221.8142292490119,
+          327.3359683794467
+        ],
+        [
+          235.8142292490119,
+          326.3359683794467
+        ],
+        [
+          240.8142292490119,
+          323.3359683794467
+        ],
+        [
+          235.8142292490119,
+          298.3359683794467
+        ],
+        [
+          238.8142292490119,
+          287.3359683794467
+        ],
+        [
+          234.8142292490119,
+          268.3359683794467
+        ],
+        [
+          257.81422924901193,
+          258.3359683794467
+        ],
+        [
+          264.81422924901193,
+          264.3359683794467
+        ],
+        [
+          256.81422924901193,
+          273.3359683794467
+        ],
+        [
+          259.81422924901193,
+          282.3359683794467
+        ],
+        [
+          284.81422924901193,
+          288.3359683794467
+        ],
+        [
+          297.81422924901193,
+          278.3359683794467
+        ],
+        [
+          288.81422924901193,
+          270.3359683794467
+        ],
+        [
+          281.81422924901193,
+          270.3359683794467
+        ],
+        [
+          283.81422924901193,
+          264.3359683794467
+        ],
+        [
+          292.81422924901193,
+          261.3359683794467
+        ],
+        [
+          308.81422924901193,
+          236.33596837944665
+        ],
+        [
+          313.81422924901193,
+          217.33596837944665
+        ],
+        [
+          309.81422924901193,
+          208.33596837944665
+        ],
+        [
+          312.81422924901193,
+          202.33596837944665
+        ],
+        [
+          308.81422924901193,
+          185.33596837944665
+        ],
+        [
+          291.81422924901193,
+          173.33596837944665
+        ],
+        [
+          269.81422924901193,
+          159.33596837944665
+        ],
+        [
+          261.81422924901193,
+          154.33596837944665
+        ],
+        [
+          264.81422924901193,
+          142.33596837944665
+        ],
+        [
+          273.81422924901193,
+          137.33596837944665
+        ],
+        [
+          278.81422924901193,
+          130.33596837944665
+        ],
+        [
+          270.81422924901193,
+          121.33596837944665
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          482.81422924901193,
+          87.18098682963114
+        ],
+        [
+          468.81422924901193,
+          92.18098682963114
+        ],
+        [
+          460.81422924901193,
+          112.18098682963114
+        ],
+        [
+          460.81422924901193,
+          129.18098682963114
+        ],
+        [
+          444.81422924901193,
+          139.18098682963114
+        ],
+        [
+          419.81422924901193,
+          155.18098682963114
+        ],
+        [
+          410.81422924901193,
+          165.18098682963114
+        ],
+        [
+          403.81422924901193,
+          170.18098682963114
+        ],
+        [
+          394.81422924901193,
+          172.18098682963114
+        ],
+        [
+          386.81422924901193,
+          170.18098682963114
+        ],
+        [
+          386.81422924901193,
+          186.18098682963114
+        ],
+        [
+          392.81422924901193,
+          184.18098682963114
+        ],
+        [
+          410.81422924901193,
+          189.18098682963114
+        ],
+        [
+          414.81422924901193,
+          194.18098682963114
+        ],
+        [
+          437.81422924901193,
+          191.18098682963114
+        ],
+        [
+          434.81422924901193,
+          206.18098682963114
+        ],
+        [
+          390.81422924901193,
+          197.18098682963114
+        ],
+        [
+          386.81422924901193,
+          197.18098682963114
+        ],
+        [
+          387.81422924901193,
+          210.18098682963114
+        ],
+        [
+          381.81422924901193,
+          214.18098682963114
+        ],
+        [
+          372.81422924901193,
+          214.18098682963114
+        ],
+        [
+          372.81422924901193,
+          218.18098682963114
+        ],
+        [
+          400.81422924901193,
+          272.18098682963114
+        ],
+        [
+          389.81422924901193,
+          274.18098682963114
+        ],
+        [
+          389.81422924901193,
+          276.18098682963114
+        ],
+        [
+          403.81422924901193,
+          284.18098682963114
+        ],
+        [
+          444.81422924901193,
+          285.18098682963114
+        ],
+        [
+          443.81422924901193,
+          261.18098682963114
+        ],
+        [
+          426.81422924901193,
+          246.18098682963114
+        ],
+        [
+          462.81422924901193,
+          258.18098682963114
+        ],
+        [
+          474.81422924901193,
+          272.18098682963114
+        ],
+        [
+          477.81422924901193,
+          282.18098682963114
+        ],
+        [
+          473.81422924901193,
+          291.18098682963114
+        ],
+        [
+          471.81422924901193,
+          298.18098682963114
+        ],
+        [
+          472.81422924901193,
+          319.18098682963114
+        ],
+        [
+          480.81422924901193,
+          334.18098682963114
+        ],
+        [
+          494.81422924901193,
+          337.18098682963114
+        ],
+        [
+          498.81422924901193,
+          331.18098682963114
+        ],
+        [
+          494.81422924901193,
+          310.18098682963114
+        ],
+        [
+          499.81422924901193,
+          299.18098682963114
+        ],
+        [
+          499.81422924901193,
+          92.18098682963114
+        ]
+      ],
+      "group_id": 0,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          370.81422924901193,
+          170.33596837944665
+        ],
+        [
+          366.81422924901193,
+          173.33596837944665
+        ],
+        [
+          365.81422924901193,
+          182.33596837944665
+        ],
+        [
+          368.81422924901193,
+          185.33596837944665
+        ]
+      ],
+      "group_id": 0,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "bottle",
+      "points": [
+        [
+          374.81422924901193,
+          159.33596837944665
+        ],
+        [
+          369.81422924901193,
+          170.33596837944665
+        ],
+        [
+          369.81422924901193,
+          210.33596837944665
+        ],
+        [
+          375.81422924901193,
+          212.33596837944665
+        ],
+        [
+          387.81422924901193,
+          209.33596837944665
+        ],
+        [
+          385.81422924901193,
+          185.33596837944665
+        ],
+        [
+          385.81422924901193,
+          168.33596837944665
+        ],
+        [
+          385.81422924901193,
+          165.33596837944665
+        ],
+        [
+          382.81422924901193,
+          159.33596837944665
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "__ignore__",
+      "points": [
+        [
+          338.81422924901193,
+          266.3359683794467
+        ],
+        [
+          313.81422924901193,
+          269.3359683794467
+        ],
+        [
+          297.81422924901193,
+          277.3359683794467
+        ],
+        [
+          282.81422924901193,
+          288.3359683794467
+        ],
+        [
+          273.81422924901193,
+          302.3359683794467
+        ],
+        [
+          272.81422924901193,
+          320.3359683794467
+        ],
+        [
+          279.81422924901193,
+          337.3359683794467
+        ],
+        [
+          428.81422924901193,
+          337.3359683794467
+        ],
+        [
+          432.81422924901193,
+          316.3359683794467
+        ],
+        [
+          423.81422924901193,
+          296.3359683794467
+        ],
+        [
+          403.81422924901193,
+          283.3359683794467
+        ],
+        [
+          370.81422924901193,
+          270.3359683794467
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    }
+  ],
+  "imagePath": "2011_000003.jpg",
+  "imageData": null,
+  "imageHeight": 338,
+  "imageWidth": 500
+}

BIN
examples/instance_segmentation/data_annotated/2011_000006.jpg


+ 530 - 0
examples/instance_segmentation/data_annotated/2011_000006.json

@@ -0,0 +1,530 @@
+{
+  "version": "4.0.0",
+  "flags": {},
+  "shapes": [
+    {
+      "label": "person",
+      "points": [
+        [
+          204.936170212766,
+          108.56382978723406
+        ],
+        [
+          183.936170212766,
+          141.56382978723406
+        ],
+        [
+          166.936170212766,
+          150.56382978723406
+        ],
+        [
+          108.93617021276599,
+          203.56382978723406
+        ],
+        [
+          92.93617021276599,
+          228.56382978723406
+        ],
+        [
+          95.93617021276599,
+          244.56382978723406
+        ],
+        [
+          105.93617021276599,
+          244.56382978723406
+        ],
+        [
+          116.93617021276599,
+          223.56382978723406
+        ],
+        [
+          163.936170212766,
+          187.56382978723406
+        ],
+        [
+          147.936170212766,
+          212.56382978723406
+        ],
+        [
+          117.93617021276599,
+          222.56382978723406
+        ],
+        [
+          108.93617021276599,
+          243.56382978723406
+        ],
+        [
+          100.93617021276599,
+          325.56382978723406
+        ],
+        [
+          135.936170212766,
+          329.56382978723406
+        ],
+        [
+          148.936170212766,
+          319.56382978723406
+        ],
+        [
+          150.936170212766,
+          295.56382978723406
+        ],
+        [
+          169.936170212766,
+          272.56382978723406
+        ],
+        [
+          171.936170212766,
+          249.56382978723406
+        ],
+        [
+          178.936170212766,
+          246.56382978723406
+        ],
+        [
+          186.936170212766,
+          225.56382978723406
+        ],
+        [
+          214.936170212766,
+          219.56382978723406
+        ],
+        [
+          242.936170212766,
+          157.56382978723406
+        ],
+        [
+          228.936170212766,
+          146.56382978723406
+        ],
+        [
+          228.936170212766,
+          125.56382978723406
+        ],
+        [
+          216.936170212766,
+          112.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          271.936170212766,
+          109.56382978723406
+        ],
+        [
+          249.936170212766,
+          110.56382978723406
+        ],
+        [
+          244.936170212766,
+          150.56382978723406
+        ],
+        [
+          215.936170212766,
+          219.56382978723406
+        ],
+        [
+          208.936170212766,
+          245.56382978723406
+        ],
+        [
+          214.936170212766,
+          220.56382978723406
+        ],
+        [
+          188.936170212766,
+          227.56382978723406
+        ],
+        [
+          170.936170212766,
+          246.56382978723406
+        ],
+        [
+          170.936170212766,
+          275.56382978723406
+        ],
+        [
+          221.936170212766,
+          278.56382978723406
+        ],
+        [
+          233.936170212766,
+          259.56382978723406
+        ],
+        [
+          246.936170212766,
+          253.56382978723406
+        ],
+        [
+          245.936170212766,
+          256.56382978723406
+        ],
+        [
+          242.936170212766,
+          251.56382978723406
+        ],
+        [
+          262.936170212766,
+          256.56382978723406
+        ],
+        [
+          304.936170212766,
+          226.56382978723406
+        ],
+        [
+          297.936170212766,
+          199.56382978723406
+        ],
+        [
+          308.936170212766,
+          164.56382978723406
+        ],
+        [
+          296.936170212766,
+          148.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          308.936170212766,
+          115.56382978723406
+        ],
+        [
+          298.936170212766,
+          145.56382978723406
+        ],
+        [
+          309.936170212766,
+          166.56382978723406
+        ],
+        [
+          297.936170212766,
+          200.56382978723406
+        ],
+        [
+          305.936170212766,
+          228.56382978723406
+        ],
+        [
+          262.936170212766,
+          258.56382978723406
+        ],
+        [
+          252.936170212766,
+          284.56382978723406
+        ],
+        [
+          272.936170212766,
+          291.56382978723406
+        ],
+        [
+          281.936170212766,
+          250.56382978723406
+        ],
+        [
+          326.936170212766,
+          235.56382978723406
+        ],
+        [
+          351.936170212766,
+          239.56382978723406
+        ],
+        [
+          365.936170212766,
+          223.56382978723406
+        ],
+        [
+          371.936170212766,
+          187.56382978723406
+        ],
+        [
+          353.936170212766,
+          168.56382978723406
+        ],
+        [
+          344.936170212766,
+          143.56382978723406
+        ],
+        [
+          336.936170212766,
+          115.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "chair",
+      "points": [
+        [
+          309.7054009819968,
+          242.94844517184941
+        ],
+        [
+          282.7054009819968,
+          251.94844517184941
+        ],
+        [
+          271.7054009819968,
+          287.9484451718494
+        ],
+        [
+          175.70540098199677,
+          275.9484451718494
+        ],
+        [
+          149.70540098199677,
+          296.9484451718494
+        ],
+        [
+          151.70540098199677,
+          319.9484451718494
+        ],
+        [
+          160.70540098199677,
+          328.9484451718494
+        ],
+        [
+          165.54250204582655,
+          375.38461538461536
+        ],
+        [
+          486.7054009819968,
+          373.9484451718494
+        ],
+        [
+          498.7054009819968,
+          336.9484451718494
+        ],
+        [
+          498.7054009819968,
+          202.94844517184941
+        ],
+        [
+          454.7054009819968,
+          193.94844517184941
+        ],
+        [
+          435.7054009819968,
+          212.94844517184941
+        ],
+        [
+          368.7054009819968,
+          224.94844517184941
+        ],
+        [
+          351.7054009819968,
+          241.94844517184941
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          425.936170212766,
+          82.56382978723406
+        ],
+        [
+          404.936170212766,
+          109.56382978723406
+        ],
+        [
+          400.936170212766,
+          114.56382978723406
+        ],
+        [
+          437.936170212766,
+          114.56382978723406
+        ],
+        [
+          448.936170212766,
+          102.56382978723406
+        ],
+        [
+          446.936170212766,
+          91.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "__ignore__",
+      "points": [
+        [
+          457.936170212766,
+          85.56382978723406
+        ],
+        [
+          439.936170212766,
+          117.56382978723406
+        ],
+        [
+          477.936170212766,
+          117.56382978723406
+        ],
+        [
+          474.936170212766,
+          87.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "sofa",
+      "points": [
+        [
+          183.936170212766,
+          140.56382978723406
+        ],
+        [
+          125.93617021276599,
+          140.56382978723406
+        ],
+        [
+          110.93617021276599,
+          187.56382978723406
+        ],
+        [
+          22.936170212765987,
+          199.56382978723406
+        ],
+        [
+          18.936170212765987,
+          218.56382978723406
+        ],
+        [
+          22.936170212765987,
+          234.56382978723406
+        ],
+        [
+          93.93617021276599,
+          239.56382978723406
+        ],
+        [
+          91.93617021276599,
+          229.56382978723406
+        ],
+        [
+          110.93617021276599,
+          203.56382978723406
+        ]
+      ],
+      "group_id": 0,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "sofa",
+      "points": [
+        [
+          103.93617021276599,
+          290.56382978723406
+        ],
+        [
+          58.93617021276599,
+          303.56382978723406
+        ],
+        [
+          97.93617021276599,
+          311.56382978723406
+        ]
+      ],
+      "group_id": 0,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "sofa",
+      "points": [
+        [
+          348.936170212766,
+          146.56382978723406
+        ],
+        [
+          472.936170212766,
+          149.56382978723406
+        ],
+        [
+          477.936170212766,
+          162.56382978723406
+        ],
+        [
+          471.936170212766,
+          196.56382978723406
+        ],
+        [
+          453.936170212766,
+          192.56382978723406
+        ],
+        [
+          434.936170212766,
+          213.56382978723406
+        ],
+        [
+          368.936170212766,
+          226.56382978723406
+        ],
+        [
+          375.936170212766,
+          187.56382978723406
+        ],
+        [
+          353.936170212766,
+          164.56382978723406
+        ]
+      ],
+      "group_id": 0,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "sofa",
+      "points": [
+        [
+          246.936170212766,
+          252.56382978723406
+        ],
+        [
+          219.936170212766,
+          277.56382978723406
+        ],
+        [
+          254.936170212766,
+          287.56382978723406
+        ],
+        [
+          261.936170212766,
+          256.56382978723406
+        ]
+      ],
+      "group_id": 0,
+      "shape_type": "polygon",
+      "flags": {}
+    }
+  ],
+  "imagePath": "2011_000006.jpg",
+  "imageData": null,
+  "imageHeight": 375,
+  "imageWidth": 500
+}

BIN
examples/instance_segmentation/data_annotated/2011_000025.jpg


+ 210 - 0
examples/instance_segmentation/data_annotated/2011_000025.json

@@ -0,0 +1,210 @@
+{
+  "version": "4.0.0",
+  "flags": {},
+  "shapes": [
+    {
+      "label": "bus",
+      "points": [
+        [
+          260.936170212766,
+          23.33306055646483
+        ],
+        [
+          193.936170212766,
+          20.33306055646483
+        ],
+        [
+          124.93617021276599,
+          40.33306055646483
+        ],
+        [
+          89.93617021276599,
+          102.33306055646483
+        ],
+        [
+          81.93617021276599,
+          151.33306055646483
+        ],
+        [
+          108.93617021276599,
+          146.33306055646483
+        ],
+        [
+          88.93617021276599,
+          245.33306055646483
+        ],
+        [
+          89.93617021276599,
+          323.33306055646483
+        ],
+        [
+          116.93617021276599,
+          368.33306055646483
+        ],
+        [
+          158.936170212766,
+          369.33306055646483
+        ],
+        [
+          165.936170212766,
+          338.33306055646483
+        ],
+        [
+          347.936170212766,
+          336.33306055646483
+        ],
+        [
+          349.936170212766,
+          370.33306055646483
+        ],
+        [
+          391.936170212766,
+          374.33306055646483
+        ],
+        [
+          403.936170212766,
+          336.33306055646483
+        ],
+        [
+          425.936170212766,
+          333.33306055646483
+        ],
+        [
+          421.936170212766,
+          282.33306055646483
+        ],
+        [
+          428.936170212766,
+          253.33306055646483
+        ],
+        [
+          428.936170212766,
+          237.33306055646483
+        ],
+        [
+          409.936170212766,
+          221.33306055646483
+        ],
+        [
+          409.936170212766,
+          151.33306055646483
+        ],
+        [
+          430.936170212766,
+          144.33306055646483
+        ],
+        [
+          433.936170212766,
+          113.33306055646483
+        ],
+        [
+          431.936170212766,
+          97.33306055646483
+        ],
+        [
+          408.936170212766,
+          91.33306055646483
+        ],
+        [
+          395.936170212766,
+          51.33306055646483
+        ],
+        [
+          338.936170212766,
+          26.33306055646483
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "bus",
+      "points": [
+        [
+          88.93617021276599,
+          115.56382978723406
+        ],
+        [
+          0.9361702127659877,
+          96.56382978723406
+        ],
+        [
+          0.0,
+          251.968085106388
+        ],
+        [
+          0.9361702127659877,
+          265.56382978723406
+        ],
+        [
+          27.936170212765987,
+          265.56382978723406
+        ],
+        [
+          29.936170212765987,
+          283.56382978723406
+        ],
+        [
+          63.93617021276599,
+          281.56382978723406
+        ],
+        [
+          89.93617021276599,
+          252.56382978723406
+        ],
+        [
+          100.93617021276599,
+          183.56382978723406
+        ],
+        [
+          108.93617021276599,
+          145.56382978723406
+        ],
+        [
+          81.93617021276599,
+          151.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "car",
+      "points": [
+        [
+          413.936170212766,
+          168.94844517184944
+        ],
+        [
+          497.936170212766,
+          168.94844517184944
+        ],
+        [
+          497.936170212766,
+          256.94844517184936
+        ],
+        [
+          431.936170212766,
+          258.94844517184936
+        ],
+        [
+          430.936170212766,
+          236.94844517184944
+        ],
+        [
+          408.936170212766,
+          218.94844517184944
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    }
+  ],
+  "imagePath": "2011_000025.jpg",
+  "imageData": null,
+  "imageHeight": 375,
+  "imageWidth": 500
+}

BIN
examples/instance_segmentation/data_dataset_coco/JPEGImages/2011_000003.jpg


BIN
examples/instance_segmentation/data_dataset_coco/JPEGImages/2011_000006.jpg


BIN
examples/instance_segmentation/data_dataset_coco/JPEGImages/2011_000025.jpg


BIN
examples/instance_segmentation/data_dataset_coco/Visualization/2011_000003.jpg


BIN
examples/instance_segmentation/data_dataset_coco/Visualization/2011_000006.jpg


BIN
examples/instance_segmentation/data_dataset_coco/Visualization/2011_000025.jpg


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
examples/instance_segmentation/data_dataset_coco/annotations.json


BIN
examples/instance_segmentation/data_dataset_voc/JPEGImages/2011_000003.jpg


BIN
examples/instance_segmentation/data_dataset_voc/JPEGImages/2011_000006.jpg


BIN
examples/instance_segmentation/data_dataset_voc/JPEGImages/2011_000025.jpg


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationClass/2011_000003.png


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationClass/2011_000006.png


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationClass/2011_000025.png


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationClassNpy/2011_000003.npy


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationClassNpy/2011_000006.npy


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationClassNpy/2011_000025.npy


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationClassVisualization/2011_000003.jpg


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationClassVisualization/2011_000006.jpg


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationClassVisualization/2011_000025.jpg


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationObject/2011_000003.png


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationObject/2011_000006.png


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationObject/2011_000025.png


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationObjectNpy/2011_000003.npy


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationObjectNpy/2011_000006.npy


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationObjectNpy/2011_000025.npy


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationObjectVisualization/2011_000003.jpg


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationObjectVisualization/2011_000006.jpg


BIN
examples/instance_segmentation/data_dataset_voc/SegmentationObjectVisualization/2011_000025.jpg


+ 21 - 0
examples/instance_segmentation/data_dataset_voc/class_names.txt

@@ -0,0 +1,21 @@
+_background_
+aeroplane
+bicycle
+bird
+boat
+bottle
+bus
+car
+cat
+chair
+cow
+diningtable
+dog
+horse
+motorbike
+person
+potted plant
+sheep
+sofa
+train
+tv/monitor

+ 203 - 0
examples/instance_segmentation/labelme2coco.py

@@ -0,0 +1,203 @@
+#!/usr/bin/env python
+
+import argparse
+import collections
+import datetime
+import glob
+import json
+import os
+import os.path as osp
+import sys
+import uuid
+
+import imgviz
+import numpy as np
+
+import labelme
+
+try:
+    import pycocotools.mask
+except ImportError:
+    print("Please install pycocotools:\n\n    pip install pycocotools\n")
+    sys.exit(1)
+
+
+def main():
+    parser = argparse.ArgumentParser(
+        formatter_class=argparse.ArgumentDefaultsHelpFormatter
+    )
+    parser.add_argument("input_dir", help="input annotated directory")
+    parser.add_argument("output_dir", help="output dataset directory")
+    parser.add_argument("--labels", help="labels file", required=True)
+    parser.add_argument("--noviz", help="no visualization", action="store_true")
+    args = parser.parse_args()
+
+    if osp.exists(args.output_dir):
+        print("Output directory already exists:", args.output_dir)
+        sys.exit(1)
+    os.makedirs(args.output_dir)
+    os.makedirs(osp.join(args.output_dir, "JPEGImages"))
+    if not args.noviz:
+        os.makedirs(osp.join(args.output_dir, "Visualization"))
+    print("Creating dataset:", args.output_dir)
+
+    now = datetime.datetime.now()
+
+    data = dict(
+        info=dict(
+            description=None,
+            url=None,
+            version=None,
+            year=now.year,
+            contributor=None,
+            date_created=now.strftime("%Y-%m-%d %H:%M:%S.%f"),
+        ),
+        licenses=[
+            dict(
+                url=None,
+                id=0,
+                name=None,
+            )
+        ],
+        images=[
+            # license, url, file_name, height, width, date_captured, id
+        ],
+        type="instances",
+        annotations=[
+            # segmentation, area, iscrowd, image_id, bbox, category_id, id
+        ],
+        categories=[
+            # supercategory, id, name
+        ],
+    )
+
+    class_name_to_id = {}
+    for i, line in enumerate(open(args.labels).readlines()):
+        class_id = i - 1  # starts with -1
+        class_name = line.strip()
+        if class_id == -1:
+            assert class_name == "__ignore__"
+            continue
+        class_name_to_id[class_name] = class_id
+        data["categories"].append(
+            dict(
+                supercategory=None,
+                id=class_id,
+                name=class_name,
+            )
+        )
+
+    out_ann_file = osp.join(args.output_dir, "annotations.json")
+    label_files = glob.glob(osp.join(args.input_dir, "*.json"))
+    for image_id, filename in enumerate(label_files):
+        print("Generating dataset from:", filename)
+
+        label_file = labelme.LabelFile(filename=filename)
+
+        base = osp.splitext(osp.basename(filename))[0]
+        out_img_file = osp.join(args.output_dir, "JPEGImages", base + ".jpg")
+
+        img = labelme.utils.img_data_to_arr(label_file.imageData)
+        imgviz.io.imsave(out_img_file, img)
+        data["images"].append(
+            dict(
+                license=0,
+                url=None,
+                file_name=osp.relpath(out_img_file, osp.dirname(out_ann_file)),
+                height=img.shape[0],
+                width=img.shape[1],
+                date_captured=None,
+                id=image_id,
+            )
+        )
+
+        masks = {}  # for area
+        segmentations = collections.defaultdict(list)  # for segmentation
+        for shape in label_file.shapes:
+            points = shape["points"]
+            label = shape["label"]
+            group_id = shape.get("group_id")
+            shape_type = shape.get("shape_type", "polygon")
+            mask = labelme.utils.shape_to_mask(img.shape[:2], points, shape_type)
+
+            if group_id is None:
+                group_id = uuid.uuid1()
+
+            instance = (label, group_id)
+
+            if instance in masks:
+                masks[instance] = masks[instance] | mask
+            else:
+                masks[instance] = mask
+
+            if shape_type == "rectangle":
+                (x1, y1), (x2, y2) = points
+                x1, x2 = sorted([x1, x2])
+                y1, y2 = sorted([y1, y2])
+                points = [x1, y1, x2, y1, x2, y2, x1, y2]
+            if shape_type == "circle":
+                (x1, y1), (x2, y2) = points
+                r = np.linalg.norm([x2 - x1, y2 - y1])
+                # r(1-cos(a/2))<x, a=2*pi/N => N>pi/arccos(1-x/r)
+                # x: tolerance of the gap between the arc and the line segment
+                n_points_circle = max(int(np.pi / np.arccos(1 - 1 / r)), 12)
+                i = np.arange(n_points_circle)
+                x = x1 + r * np.sin(2 * np.pi / n_points_circle * i)
+                y = y1 + r * np.cos(2 * np.pi / n_points_circle * i)
+                points = np.stack((x, y), axis=1).flatten().tolist()
+            else:
+                points = np.asarray(points).flatten().tolist()
+
+            segmentations[instance].append(points)
+        segmentations = dict(segmentations)
+
+        for instance, mask in masks.items():
+            cls_name, group_id = instance
+            if cls_name not in class_name_to_id:
+                continue
+            cls_id = class_name_to_id[cls_name]
+
+            mask = np.asfortranarray(mask.astype(np.uint8))
+            mask = pycocotools.mask.encode(mask)
+            area = float(pycocotools.mask.area(mask))
+            bbox = pycocotools.mask.toBbox(mask).flatten().tolist()
+
+            data["annotations"].append(
+                dict(
+                    id=len(data["annotations"]),
+                    image_id=image_id,
+                    category_id=cls_id,
+                    segmentation=segmentations[instance],
+                    area=area,
+                    bbox=bbox,
+                    iscrowd=0,
+                )
+            )
+
+        if not args.noviz:
+            viz = img
+            if masks:
+                labels, captions, masks = zip(
+                    *[
+                        (class_name_to_id[cnm], cnm, msk)
+                        for (cnm, gid), msk in masks.items()
+                        if cnm in class_name_to_id
+                    ]
+                )
+                viz = imgviz.instances2rgb(
+                    image=img,
+                    labels=labels,
+                    masks=masks,
+                    captions=captions,
+                    font_size=15,
+                    line_width=2,
+                )
+            out_viz_file = osp.join(args.output_dir, "Visualization", base + ".jpg")
+            imgviz.io.imsave(out_viz_file, viz)
+
+    with open(out_ann_file, "w") as f:
+        json.dump(data, f)
+
+
+if __name__ == "__main__":
+    main()

+ 156 - 0
examples/instance_segmentation/labelme2voc.py

@@ -0,0 +1,156 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+
+import argparse
+import glob
+import os
+import os.path as osp
+import sys
+
+import imgviz
+import numpy as np
+
+import labelme
+
+
+def main():
+    parser = argparse.ArgumentParser(
+        formatter_class=argparse.ArgumentDefaultsHelpFormatter
+    )
+    parser.add_argument("input_dir", help="Input annotated directory")
+    parser.add_argument("output_dir", help="Output dataset directory")
+    parser.add_argument(
+        "--labels", help="Labels file or comma separated text", required=True
+    )
+    parser.add_argument(
+        "--noobject", help="Flag not to generate object label", action="store_true"
+    )
+    parser.add_argument(
+        "--nonpy", help="Flag not to generate .npy files", action="store_true"
+    )
+    parser.add_argument(
+        "--noviz", help="Flag to disable visualization", action="store_true"
+    )
+    args = parser.parse_args()
+
+    if osp.exists(args.output_dir):
+        print("Output directory already exists:", args.output_dir)
+        sys.exit(1)
+    os.makedirs(args.output_dir)
+    os.makedirs(osp.join(args.output_dir, "JPEGImages"))
+    os.makedirs(osp.join(args.output_dir, "SegmentationClass"))
+    if not args.nonpy:
+        os.makedirs(osp.join(args.output_dir, "SegmentationClassNpy"))
+    if not args.noviz:
+        os.makedirs(osp.join(args.output_dir, "SegmentationClassVisualization"))
+    if not args.noobject:
+        os.makedirs(osp.join(args.output_dir, "SegmentationObject"))
+        if not args.nonpy:
+            os.makedirs(osp.join(args.output_dir, "SegmentationObjectNpy"))
+        if not args.noviz:
+            os.makedirs(osp.join(args.output_dir, "SegmentationObjectVisualization"))
+    print("Creating dataset:", args.output_dir)
+
+    if osp.exists(args.labels):
+        with open(args.labels) as f:
+            labels = [label.strip() for label in f if label]
+    else:
+        labels = [label.strip() for label in args.labels.split(",")]
+
+    class_names = []
+    class_name_to_id = {}
+    for i, label in enumerate(labels):
+        class_id = i - 1  # starts with -1
+        class_name = label.strip()
+        class_name_to_id[class_name] = class_id
+        if class_id == -1:
+            assert class_name == "__ignore__"
+            continue
+        elif class_id == 0:
+            assert class_name == "_background_"
+        class_names.append(class_name)
+    class_names = tuple(class_names)
+    print("class_names:", class_names)
+    out_class_names_file = osp.join(args.output_dir, "class_names.txt")
+    with open(out_class_names_file, "w") as f:
+        f.writelines("\n".join(class_names))
+    print("Saved class_names:", out_class_names_file)
+
+    for filename in sorted(glob.glob(osp.join(args.input_dir, "*.json"))):
+        print("Generating dataset from:", filename)
+
+        label_file = labelme.LabelFile(filename=filename)
+
+        base = osp.splitext(osp.basename(filename))[0]
+        out_img_file = osp.join(args.output_dir, "JPEGImages", base + ".jpg")
+        out_clsp_file = osp.join(args.output_dir, "SegmentationClass", base + ".png")
+        if not args.nonpy:
+            out_cls_file = osp.join(
+                args.output_dir, "SegmentationClassNpy", base + ".npy"
+            )
+        if not args.noviz:
+            out_clsv_file = osp.join(
+                args.output_dir,
+                "SegmentationClassVisualization",
+                base + ".jpg",
+            )
+        if not args.noobject:
+            out_insp_file = osp.join(
+                args.output_dir, "SegmentationObject", base + ".png"
+            )
+            if not args.nonpy:
+                out_ins_file = osp.join(
+                    args.output_dir, "SegmentationObjectNpy", base + ".npy"
+                )
+            if not args.noviz:
+                out_insv_file = osp.join(
+                    args.output_dir,
+                    "SegmentationObjectVisualization",
+                    base + ".jpg",
+                )
+
+        img = labelme.utils.img_data_to_arr(label_file.imageData)
+        imgviz.io.imsave(out_img_file, img)
+
+        cls, ins = labelme.utils.shapes_to_label(
+            img_shape=img.shape,
+            shapes=label_file.shapes,
+            label_name_to_value=class_name_to_id,
+        )
+        ins[cls == -1] = 0  # ignore it.
+
+        # class label
+        labelme.utils.lblsave(out_clsp_file, cls)
+        if not args.nonpy:
+            np.save(out_cls_file, cls)
+        if not args.noviz:
+            clsv = imgviz.label2rgb(
+                cls,
+                imgviz.rgb2gray(img),
+                label_names=class_names,
+                font_size=15,
+                loc="rb",
+            )
+            imgviz.io.imsave(out_clsv_file, clsv)
+
+        if not args.noobject:
+            # instance label
+            labelme.utils.lblsave(out_insp_file, ins)
+            if not args.nonpy:
+                np.save(out_ins_file, ins)
+            if not args.noviz:
+                instance_ids = np.unique(ins)
+                instance_names = [str(i) for i in range(max(instance_ids) + 1)]
+                insv = imgviz.label2rgb(
+                    ins,
+                    imgviz.rgb2gray(img),
+                    label_names=instance_names,
+                    font_size=15,
+                    loc="rb",
+                )
+                imgviz.io.imsave(out_insv_file, insv)
+
+
+if __name__ == "__main__":
+    main()

+ 22 - 0
examples/instance_segmentation/labels.txt

@@ -0,0 +1,22 @@
+__ignore__
+_background_
+aeroplane
+bicycle
+bird
+boat
+bottle
+bus
+car
+cat
+chair
+cow
+diningtable
+dog
+horse
+motorbike
+person
+potted plant
+sheep
+sofa
+train
+tv/monitor

BIN
examples/primitives/primitives.jpg


+ 130 - 0
examples/primitives/primitives.json

@@ -0,0 +1,130 @@
+{
+  "version": "4.0.0",
+  "flags": {},
+  "shapes": [
+    {
+      "label": "rectangle",
+      "points": [
+        [
+          32.0,
+          35.0
+        ],
+        [
+          132.0,
+          135.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    },
+    {
+      "label": "circle",
+      "points": [
+        [
+          195.0,
+          84.0
+        ],
+        [
+          225.0,
+          125.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "circle",
+      "flags": {}
+    },
+    {
+      "label": "rectangle",
+      "points": [
+        [
+          391.0,
+          33.0
+        ],
+        [
+          542.0,
+          135.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "rectangle",
+      "flags": {}
+    },
+    {
+      "label": "polygon",
+      "points": [
+        [
+          69.0,
+          318.0
+        ],
+        [
+          45.0,
+          403.0
+        ],
+        [
+          173.0,
+          406.0
+        ],
+        [
+          198.0,
+          321.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "line",
+      "points": [
+        [
+          188.0,
+          178.0
+        ],
+        [
+          160.0,
+          224.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "line",
+      "flags": {}
+    },
+    {
+      "label": "point",
+      "points": [
+        [
+          345.0,
+          174.0
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "point",
+      "flags": {}
+    },
+    {
+      "label": "line_strip",
+      "points": [
+        [
+          440.53703703703707,
+          181.46296296296293
+        ],
+        [
+          402.53703703703707,
+          274.46296296296293
+        ],
+        [
+          544.5370370370371,
+          275.46296296296293
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "linestrip",
+      "flags": {}
+    }
+  ],
+  "imagePath": "primitives.jpg",
+  "imageData": null,
+  "imageHeight": 450,
+  "imageWidth": 560
+}

BIN
examples/semantic_segmentation/.readme/annotation.jpg


BIN
examples/semantic_segmentation/.readme/draw_label_png.jpg


+ 36 - 0
examples/semantic_segmentation/README.md

@@ -0,0 +1,36 @@
+# Semantic Segmentation Example
+
+## Annotation
+
+```bash
+labelme data_annotated --labels labels.txt --nodata --validatelabel exact --config '{shift_auto_shape_color: -2}'
+```
+
+![](.readme/annotation.jpg)
+
+
+## Convert to VOC-format Dataset
+
+```bash
+# It generates:
+#   - data_dataset_voc/JPEGImages
+#   - data_dataset_voc/SegmentationClass
+#   - data_dataset_voc/SegmentationClassNpy
+#   - data_dataset_voc/SegmentationClassVisualization
+./labelme2voc.py data_annotated data_dataset_voc --labels labels.txt --noobject
+```
+
+<img src="data_dataset_voc/JPEGImages/2011_000003.jpg" width="33%" /> <img src="data_dataset_voc/SegmentationClass/2011_000003.png" width="33%" /> <img src="data_dataset_voc/SegmentationClassVisualization/2011_000003.jpg" width="33%" />
+
+Fig 1. JPEG image (left), PNG label (center), JPEG label visualization (right)  
+
+
+Note that the label file contains only very low label values (ex. `0, 4, 14`), and
+`255` indicates the `__ignore__` label value (`-1` in the npy file).  
+You can see the label PNG file by following.
+
+```bash
+labelme_draw_label_png data_dataset_voc/SegmentationClass/2011_000003.png
+```
+
+<img src=".readme/draw_label_png.jpg" width="33%" />

BIN
examples/semantic_segmentation/data_annotated/2011_000003.jpg


+ 478 - 0
examples/semantic_segmentation/data_annotated/2011_000003.json

@@ -0,0 +1,478 @@
+{
+  "version": "4.0.0",
+  "flags": {},
+  "shapes": [
+    {
+      "label": "person",
+      "points": [
+        [
+          250.8142292490119,
+          106.96696468940974
+        ],
+        [
+          229.8142292490119,
+          118.96696468940974
+        ],
+        [
+          221.8142292490119,
+          134.96696468940974
+        ],
+        [
+          223.8142292490119,
+          147.96696468940974
+        ],
+        [
+          217.8142292490119,
+          160.96696468940974
+        ],
+        [
+          202.8142292490119,
+          167.96696468940974
+        ],
+        [
+          192.8142292490119,
+          199.96696468940974
+        ],
+        [
+          194.8142292490119,
+          221.96696468940974
+        ],
+        [
+          199.8142292490119,
+          226.96696468940974
+        ],
+        [
+          191.8142292490119,
+          233.96696468940974
+        ],
+        [
+          197.8142292490119,
+          263.9669646894098
+        ],
+        [
+          213.8142292490119,
+          294.9669646894098
+        ],
+        [
+          214.8142292490119,
+          319.9669646894098
+        ],
+        [
+          221.8142292490119,
+          326.9669646894098
+        ],
+        [
+          235.8142292490119,
+          325.9669646894098
+        ],
+        [
+          240.8142292490119,
+          322.9669646894098
+        ],
+        [
+          235.8142292490119,
+          297.9669646894098
+        ],
+        [
+          238.8142292490119,
+          286.9669646894098
+        ],
+        [
+          234.8142292490119,
+          267.9669646894098
+        ],
+        [
+          257.81422924901193,
+          257.9669646894098
+        ],
+        [
+          264.81422924901193,
+          263.9669646894098
+        ],
+        [
+          256.81422924901193,
+          272.9669646894098
+        ],
+        [
+          259.81422924901193,
+          281.9669646894098
+        ],
+        [
+          284.81422924901193,
+          287.9669646894098
+        ],
+        [
+          297.81422924901193,
+          277.9669646894098
+        ],
+        [
+          288.81422924901193,
+          269.9669646894098
+        ],
+        [
+          281.81422924901193,
+          269.9669646894098
+        ],
+        [
+          283.81422924901193,
+          263.9669646894098
+        ],
+        [
+          292.81422924901193,
+          260.9669646894098
+        ],
+        [
+          308.81422924901193,
+          235.96696468940974
+        ],
+        [
+          313.81422924901193,
+          216.96696468940974
+        ],
+        [
+          309.81422924901193,
+          207.96696468940974
+        ],
+        [
+          312.81422924901193,
+          201.96696468940974
+        ],
+        [
+          308.81422924901193,
+          184.96696468940974
+        ],
+        [
+          291.81422924901193,
+          172.96696468940974
+        ],
+        [
+          269.81422924901193,
+          158.96696468940974
+        ],
+        [
+          261.81422924901193,
+          153.96696468940974
+        ],
+        [
+          264.81422924901193,
+          141.96696468940974
+        ],
+        [
+          273.81422924901193,
+          136.96696468940974
+        ],
+        [
+          278.81422924901193,
+          129.96696468940974
+        ],
+        [
+          270.81422924901193,
+          120.96696468940974
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          482.81422924901193,
+          85.33596837944665
+        ],
+        [
+          468.81422924901193,
+          90.33596837944665
+        ],
+        [
+          460.81422924901193,
+          110.33596837944665
+        ],
+        [
+          460.81422924901193,
+          127.33596837944665
+        ],
+        [
+          444.81422924901193,
+          137.33596837944665
+        ],
+        [
+          419.81422924901193,
+          153.33596837944665
+        ],
+        [
+          410.81422924901193,
+          163.33596837944665
+        ],
+        [
+          403.81422924901193,
+          168.33596837944665
+        ],
+        [
+          394.81422924901193,
+          170.33596837944665
+        ],
+        [
+          386.81422924901193,
+          168.33596837944665
+        ],
+        [
+          386.81422924901193,
+          184.33596837944665
+        ],
+        [
+          392.81422924901193,
+          182.33596837944665
+        ],
+        [
+          410.81422924901193,
+          187.33596837944665
+        ],
+        [
+          414.81422924901193,
+          192.33596837944665
+        ],
+        [
+          437.81422924901193,
+          189.33596837944665
+        ],
+        [
+          434.81422924901193,
+          204.33596837944665
+        ],
+        [
+          390.81422924901193,
+          195.33596837944665
+        ],
+        [
+          386.81422924901193,
+          195.33596837944665
+        ],
+        [
+          387.81422924901193,
+          208.33596837944665
+        ],
+        [
+          381.81422924901193,
+          212.33596837944665
+        ],
+        [
+          372.81422924901193,
+          212.33596837944665
+        ],
+        [
+          372.81422924901193,
+          216.33596837944665
+        ],
+        [
+          400.81422924901193,
+          270.3359683794467
+        ],
+        [
+          389.81422924901193,
+          272.3359683794467
+        ],
+        [
+          389.81422924901193,
+          274.3359683794467
+        ],
+        [
+          403.81422924901193,
+          282.3359683794467
+        ],
+        [
+          444.81422924901193,
+          283.3359683794467
+        ],
+        [
+          443.81422924901193,
+          259.3359683794467
+        ],
+        [
+          426.81422924901193,
+          244.33596837944665
+        ],
+        [
+          462.81422924901193,
+          256.3359683794467
+        ],
+        [
+          474.81422924901193,
+          270.3359683794467
+        ],
+        [
+          477.81422924901193,
+          280.3359683794467
+        ],
+        [
+          473.81422924901193,
+          289.3359683794467
+        ],
+        [
+          471.81422924901193,
+          296.3359683794467
+        ],
+        [
+          472.81422924901193,
+          317.3359683794467
+        ],
+        [
+          480.81422924901193,
+          332.3359683794467
+        ],
+        [
+          494.81422924901193,
+          335.3359683794467
+        ],
+        [
+          498.81422924901193,
+          329.3359683794467
+        ],
+        [
+          494.81422924901193,
+          308.3359683794467
+        ],
+        [
+          499.81422924901193,
+          297.3359683794467
+        ],
+        [
+          499.81422924901193,
+          90.33596837944665
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          370.81422924901193,
+          170.33596837944665
+        ],
+        [
+          366.81422924901193,
+          173.33596837944665
+        ],
+        [
+          365.81422924901193,
+          182.33596837944665
+        ],
+        [
+          368.81422924901193,
+          185.33596837944665
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "bottle",
+      "points": [
+        [
+          374.81422924901193,
+          159.33596837944665
+        ],
+        [
+          369.81422924901193,
+          170.33596837944665
+        ],
+        [
+          369.81422924901193,
+          210.33596837944665
+        ],
+        [
+          375.81422924901193,
+          212.33596837944665
+        ],
+        [
+          387.81422924901193,
+          209.33596837944665
+        ],
+        [
+          385.81422924901193,
+          185.33596837944665
+        ],
+        [
+          385.81422924901193,
+          168.33596837944665
+        ],
+        [
+          385.81422924901193,
+          165.33596837944665
+        ],
+        [
+          382.81422924901193,
+          159.33596837944665
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "__ignore__",
+      "points": [
+        [
+          338.81422924901193,
+          266.3359683794467
+        ],
+        [
+          313.81422924901193,
+          269.3359683794467
+        ],
+        [
+          297.81422924901193,
+          277.3359683794467
+        ],
+        [
+          282.81422924901193,
+          288.3359683794467
+        ],
+        [
+          273.81422924901193,
+          302.3359683794467
+        ],
+        [
+          272.81422924901193,
+          320.3359683794467
+        ],
+        [
+          279.81422924901193,
+          337.3359683794467
+        ],
+        [
+          428.81422924901193,
+          337.3359683794467
+        ],
+        [
+          432.81422924901193,
+          316.3359683794467
+        ],
+        [
+          423.81422924901193,
+          296.3359683794467
+        ],
+        [
+          403.81422924901193,
+          283.3359683794467
+        ],
+        [
+          370.81422924901193,
+          270.3359683794467
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    }
+  ],
+  "imagePath": "2011_000003.jpg",
+  "imageData": null,
+  "imageHeight": 338,
+  "imageWidth": 500
+}

BIN
examples/semantic_segmentation/data_annotated/2011_000006.jpg


+ 530 - 0
examples/semantic_segmentation/data_annotated/2011_000006.json

@@ -0,0 +1,530 @@
+{
+  "version": "4.0.0",
+  "flags": {},
+  "shapes": [
+    {
+      "label": "person",
+      "points": [
+        [
+          204.936170212766,
+          108.56382978723406
+        ],
+        [
+          183.936170212766,
+          141.56382978723406
+        ],
+        [
+          166.936170212766,
+          150.56382978723406
+        ],
+        [
+          108.93617021276599,
+          203.56382978723406
+        ],
+        [
+          92.93617021276599,
+          228.56382978723406
+        ],
+        [
+          95.93617021276599,
+          244.56382978723406
+        ],
+        [
+          105.93617021276599,
+          244.56382978723406
+        ],
+        [
+          116.93617021276599,
+          223.56382978723406
+        ],
+        [
+          163.936170212766,
+          187.56382978723406
+        ],
+        [
+          147.936170212766,
+          212.56382978723406
+        ],
+        [
+          117.93617021276599,
+          222.56382978723406
+        ],
+        [
+          108.93617021276599,
+          243.56382978723406
+        ],
+        [
+          100.93617021276599,
+          325.56382978723406
+        ],
+        [
+          135.936170212766,
+          329.56382978723406
+        ],
+        [
+          148.936170212766,
+          319.56382978723406
+        ],
+        [
+          150.936170212766,
+          295.56382978723406
+        ],
+        [
+          169.936170212766,
+          272.56382978723406
+        ],
+        [
+          171.936170212766,
+          249.56382978723406
+        ],
+        [
+          178.936170212766,
+          246.56382978723406
+        ],
+        [
+          186.936170212766,
+          225.56382978723406
+        ],
+        [
+          214.936170212766,
+          219.56382978723406
+        ],
+        [
+          242.936170212766,
+          157.56382978723406
+        ],
+        [
+          228.936170212766,
+          146.56382978723406
+        ],
+        [
+          228.936170212766,
+          125.56382978723406
+        ],
+        [
+          216.936170212766,
+          112.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          271.936170212766,
+          109.56382978723406
+        ],
+        [
+          249.936170212766,
+          110.56382978723406
+        ],
+        [
+          244.936170212766,
+          150.56382978723406
+        ],
+        [
+          215.936170212766,
+          219.56382978723406
+        ],
+        [
+          208.936170212766,
+          245.56382978723406
+        ],
+        [
+          214.936170212766,
+          220.56382978723406
+        ],
+        [
+          188.936170212766,
+          227.56382978723406
+        ],
+        [
+          170.936170212766,
+          246.56382978723406
+        ],
+        [
+          170.936170212766,
+          275.56382978723406
+        ],
+        [
+          221.936170212766,
+          278.56382978723406
+        ],
+        [
+          233.936170212766,
+          259.56382978723406
+        ],
+        [
+          246.936170212766,
+          253.56382978723406
+        ],
+        [
+          245.936170212766,
+          256.56382978723406
+        ],
+        [
+          242.936170212766,
+          251.56382978723406
+        ],
+        [
+          262.936170212766,
+          256.56382978723406
+        ],
+        [
+          304.936170212766,
+          226.56382978723406
+        ],
+        [
+          297.936170212766,
+          199.56382978723406
+        ],
+        [
+          308.936170212766,
+          164.56382978723406
+        ],
+        [
+          296.936170212766,
+          148.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          308.936170212766,
+          115.56382978723406
+        ],
+        [
+          298.936170212766,
+          145.56382978723406
+        ],
+        [
+          309.936170212766,
+          166.56382978723406
+        ],
+        [
+          297.936170212766,
+          200.56382978723406
+        ],
+        [
+          305.936170212766,
+          228.56382978723406
+        ],
+        [
+          262.936170212766,
+          258.56382978723406
+        ],
+        [
+          252.936170212766,
+          284.56382978723406
+        ],
+        [
+          272.936170212766,
+          291.56382978723406
+        ],
+        [
+          281.936170212766,
+          250.56382978723406
+        ],
+        [
+          326.936170212766,
+          235.56382978723406
+        ],
+        [
+          351.936170212766,
+          239.56382978723406
+        ],
+        [
+          365.936170212766,
+          223.56382978723406
+        ],
+        [
+          371.936170212766,
+          187.56382978723406
+        ],
+        [
+          353.936170212766,
+          168.56382978723406
+        ],
+        [
+          344.936170212766,
+          143.56382978723406
+        ],
+        [
+          336.936170212766,
+          115.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "chair",
+      "points": [
+        [
+          308.936170212766,
+          243.33306055646483
+        ],
+        [
+          281.936170212766,
+          252.33306055646483
+        ],
+        [
+          270.936170212766,
+          288.33306055646483
+        ],
+        [
+          174.936170212766,
+          276.33306055646483
+        ],
+        [
+          148.936170212766,
+          297.33306055646483
+        ],
+        [
+          150.936170212766,
+          320.33306055646483
+        ],
+        [
+          159.936170212766,
+          329.33306055646483
+        ],
+        [
+          164.77327127659578,
+          375.7692307692308
+        ],
+        [
+          485.936170212766,
+          374.33306055646483
+        ],
+        [
+          497.936170212766,
+          337.33306055646483
+        ],
+        [
+          497.936170212766,
+          203.33306055646483
+        ],
+        [
+          453.936170212766,
+          194.33306055646483
+        ],
+        [
+          434.936170212766,
+          213.33306055646483
+        ],
+        [
+          367.936170212766,
+          225.33306055646483
+        ],
+        [
+          350.936170212766,
+          242.33306055646483
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "person",
+      "points": [
+        [
+          425.936170212766,
+          82.56382978723406
+        ],
+        [
+          404.936170212766,
+          109.56382978723406
+        ],
+        [
+          400.936170212766,
+          114.56382978723406
+        ],
+        [
+          437.936170212766,
+          114.56382978723406
+        ],
+        [
+          448.936170212766,
+          102.56382978723406
+        ],
+        [
+          446.936170212766,
+          91.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "__ignore__",
+      "points": [
+        [
+          457.936170212766,
+          85.56382978723406
+        ],
+        [
+          439.936170212766,
+          117.56382978723406
+        ],
+        [
+          477.936170212766,
+          117.56382978723406
+        ],
+        [
+          474.936170212766,
+          87.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "sofa",
+      "points": [
+        [
+          183.936170212766,
+          140.56382978723406
+        ],
+        [
+          125.93617021276599,
+          140.56382978723406
+        ],
+        [
+          110.93617021276599,
+          187.56382978723406
+        ],
+        [
+          22.936170212765987,
+          199.56382978723406
+        ],
+        [
+          18.936170212765987,
+          218.56382978723406
+        ],
+        [
+          22.936170212765987,
+          234.56382978723406
+        ],
+        [
+          93.93617021276599,
+          239.56382978723406
+        ],
+        [
+          91.93617021276599,
+          229.56382978723406
+        ],
+        [
+          110.93617021276599,
+          203.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "sofa",
+      "points": [
+        [
+          103.93617021276599,
+          290.56382978723406
+        ],
+        [
+          58.93617021276599,
+          303.56382978723406
+        ],
+        [
+          97.93617021276599,
+          311.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "sofa",
+      "points": [
+        [
+          348.936170212766,
+          146.56382978723406
+        ],
+        [
+          472.936170212766,
+          149.56382978723406
+        ],
+        [
+          477.936170212766,
+          162.56382978723406
+        ],
+        [
+          471.936170212766,
+          196.56382978723406
+        ],
+        [
+          453.936170212766,
+          192.56382978723406
+        ],
+        [
+          434.936170212766,
+          213.56382978723406
+        ],
+        [
+          368.936170212766,
+          226.56382978723406
+        ],
+        [
+          375.936170212766,
+          187.56382978723406
+        ],
+        [
+          353.936170212766,
+          164.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "sofa",
+      "points": [
+        [
+          246.936170212766,
+          252.56382978723406
+        ],
+        [
+          219.936170212766,
+          277.56382978723406
+        ],
+        [
+          254.936170212766,
+          287.56382978723406
+        ],
+        [
+          261.936170212766,
+          256.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    }
+  ],
+  "imagePath": "2011_000006.jpg",
+  "imageData": null,
+  "imageHeight": 375,
+  "imageWidth": 500
+}

BIN
examples/semantic_segmentation/data_annotated/2011_000025.jpg


+ 210 - 0
examples/semantic_segmentation/data_annotated/2011_000025.json

@@ -0,0 +1,210 @@
+{
+  "version": "4.0.0",
+  "flags": {},
+  "shapes": [
+    {
+      "label": "bus",
+      "points": [
+        [
+          260.936170212766,
+          22.948445171849443
+        ],
+        [
+          193.936170212766,
+          19.948445171849443
+        ],
+        [
+          124.93617021276599,
+          39.94844517184944
+        ],
+        [
+          89.93617021276599,
+          101.94844517184944
+        ],
+        [
+          81.93617021276599,
+          150.94844517184944
+        ],
+        [
+          108.93617021276599,
+          145.94844517184944
+        ],
+        [
+          88.93617021276599,
+          244.94844517184944
+        ],
+        [
+          89.93617021276599,
+          322.94844517184936
+        ],
+        [
+          116.93617021276599,
+          367.94844517184936
+        ],
+        [
+          158.936170212766,
+          368.94844517184936
+        ],
+        [
+          165.936170212766,
+          337.94844517184936
+        ],
+        [
+          347.936170212766,
+          335.94844517184936
+        ],
+        [
+          349.936170212766,
+          369.94844517184936
+        ],
+        [
+          391.936170212766,
+          373.94844517184936
+        ],
+        [
+          403.936170212766,
+          335.94844517184936
+        ],
+        [
+          425.936170212766,
+          332.94844517184936
+        ],
+        [
+          421.936170212766,
+          281.94844517184936
+        ],
+        [
+          428.936170212766,
+          252.94844517184944
+        ],
+        [
+          428.936170212766,
+          236.94844517184944
+        ],
+        [
+          409.936170212766,
+          220.94844517184944
+        ],
+        [
+          409.936170212766,
+          150.94844517184944
+        ],
+        [
+          430.936170212766,
+          143.94844517184944
+        ],
+        [
+          433.936170212766,
+          112.94844517184944
+        ],
+        [
+          431.936170212766,
+          96.94844517184944
+        ],
+        [
+          408.936170212766,
+          90.94844517184944
+        ],
+        [
+          395.936170212766,
+          50.94844517184944
+        ],
+        [
+          338.936170212766,
+          25.948445171849443
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "bus",
+      "points": [
+        [
+          88.93617021276599,
+          115.56382978723406
+        ],
+        [
+          0.9361702127659877,
+          96.56382978723406
+        ],
+        [
+          0.0,
+          251.968085106388
+        ],
+        [
+          0.9361702127659877,
+          265.56382978723406
+        ],
+        [
+          27.936170212765987,
+          265.56382978723406
+        ],
+        [
+          29.936170212765987,
+          283.56382978723406
+        ],
+        [
+          63.93617021276599,
+          281.56382978723406
+        ],
+        [
+          89.93617021276599,
+          252.56382978723406
+        ],
+        [
+          100.93617021276599,
+          183.56382978723406
+        ],
+        [
+          108.93617021276599,
+          145.56382978723406
+        ],
+        [
+          81.93617021276599,
+          151.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    },
+    {
+      "label": "car",
+      "points": [
+        [
+          413.936170212766,
+          168.56382978723406
+        ],
+        [
+          497.936170212766,
+          168.56382978723406
+        ],
+        [
+          497.936170212766,
+          256.56382978723406
+        ],
+        [
+          431.936170212766,
+          258.56382978723406
+        ],
+        [
+          430.936170212766,
+          236.56382978723406
+        ],
+        [
+          408.936170212766,
+          218.56382978723406
+        ]
+      ],
+      "group_id": null,
+      "shape_type": "polygon",
+      "flags": {}
+    }
+  ],
+  "imagePath": "2011_000025.jpg",
+  "imageData": null,
+  "imageHeight": 375,
+  "imageWidth": 500
+}

BIN
examples/semantic_segmentation/data_dataset_voc/JPEGImages/2011_000003.jpg


BIN
examples/semantic_segmentation/data_dataset_voc/JPEGImages/2011_000006.jpg


BIN
examples/semantic_segmentation/data_dataset_voc/JPEGImages/2011_000025.jpg


BIN
examples/semantic_segmentation/data_dataset_voc/SegmentationClass/2011_000003.png


BIN
examples/semantic_segmentation/data_dataset_voc/SegmentationClass/2011_000006.png


BIN
examples/semantic_segmentation/data_dataset_voc/SegmentationClass/2011_000025.png


Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff