Giter VIP home page Giter VIP logo

candy-machine's Introduction

Candy Machine - Manual Image Tagger

Web-Based Manual Image Tagger for Training Custom Stable Diffusion LORAs & DreamBooth Models

Screenshot of Candy Machine

Candy Machine is a nascent image tagger for manually tagging small datasets (< 1k images) with .txt caption files:

  • Customizable tag layout for consistent tagging

  • Placeholder tag templates: i.e. {type} clothes, where {type} can be specified when adding a tag

  • In-built image editing (crop, rotate and flip horizontal)

  • Tag suggestions using wd-v1-4-convnext-tagger.v3 when creating a new project

  • Automatic file conversion to .png from .webp, .avif, .gif, etc

  • Progress % pie chart - for those times when you wonder 'am I done yet?!'

  • Keyboard shortcuts - press '?' for a list

  • and more coming soon!

Candy Machine runs entirely on your local machine in "single player" mode. No information is transmitted to any 3rd party system.

Built-In Image Editor

Edit Image Screenshot

Why?

I was inspired by this Reddit post about how to best tag small image datasets, focusing mainly on consistency.

I've also never loved the "fiddly" parts of building a dataset - converting images, renaming them, cropping etc. I want to make building datasets quick, easy and, who knows, maybe even fun!

H/T to BinaryAlley also for their prototype.

Requirements:

  • Git
  • Python 3

Free for Personal, Non-Commercial Use.

This software is entirely free for personal, non-commercial use. If you're using it in a business context or for commercial use (i.e. to make money from it), please contact me to arrange a paid license. This will help support my development costs.

How to Run on Windows

git clone [email protected]:mikeknapp/candy-machine.git
cd candy-machine
run

A browser window should automatically open: http://127.0.0.1:5000/

How to Run on MacOS/Unix

(Note, I haven't tested this yet, there may be bugs!)

git clone [email protected]:mikeknapp/candy-machine.git
cd candy-machine
chmod +x run.sh
./run.sh

A browser window should automatically open: http://127.0.0.1:5000/

Using the GPU for Image Tagging

Requires CUDA 12.2 and cuDNN8.x.

  1. Activate the Python venv. (Look inside run.bat for clues on how to do that.)

  2. Install onnxruntime-gpu

pip install onnxruntime-gpu --extra-index-url \
    https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/

Known Issues

  • Can't edit a project's tag layout or the default tag layout inside the app. (Workaround: edit default_categories.json in the server directory, or a project's categories.json. For the latter, be sure not to remove tags that are being actively used, otherwise they will be orphaned at the end of the tag list if you save that image in the future.)

  • Can't add more images to a project! (Workaround: create a new project. I know, not ideal.)

  • Can't edit the trigger word / synonyms. (Workaround: edit the project's config.json and all existing .txt caption files.)

Feature Pipeline

  • Delete tags
  • Sort tags by usage
  • Add more images!
  • Edit trigger word / synonyms
  • Image zoom
  • Color picker -> color name
  • Find and replace tags (across the project)
  • Export wizard to prepare the data and generate recommended settings for Kohya SS
  • Customize tag layout from import analysis
  • Saved presets for tag layouts (i.e. photography, anime, style LORAs etc)
  • Watermark removal (inpainting?)
  • Detection and removal of Nightshade-poisoned images etc from the dataset (to respect the wishes of copyright holders and protect your dataset).
  • Maybe in the future: Automated image search to find more images?

Want to Contribute?

Tech stack:

  • Basic Python HTTP server - using virtual env
  • Parcel for building the JS and CSS bundles
  • TypeScript
  • Flowbite React for the UI components
  • Tailwind CSS for styling

Before spending any time writing code, please open an issue with your proposal so we can discuss. Thanks!

Virtual Env Setup (Windows):

python -m venv venv
call .\venv\Scripts\activate
pip install -r requirements.txt

Run the UI:

Prerequisites: Node and Yarn.

cd ui
yarn start

Run the Server:

cd server
python main.py

Questions, Comments, Feedback?

Please send me a message, or open an issue. Thanks!

candy-machine's People

Contributors

mikeknapp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

candy-machine's Issues

[Feature Request] Cogvlm v7 and internlm-xcomposer2-vl-7b

I have used cogvlm v7 (through a guy on patreon) to caption 120,000 images and itndies a very good job, it does it even on some uncensored photos (in detail) if I use a special prompt with English and Chinese characters. I also found internlm-xcomposer2-vl-7b to be pretty good but seemed a bit more censored.

Would love to see these two models added.l as options to this repo. Also not sure if this is just sci-fi yet. But an ability fir a clip vision to follow directions such as in certain scenarios if the image will not crop to 1024x1024 without cutting out the subject to put black bars on the left and right side (poor man's masking) and always worked well for me as long as most if the dataset wasn't like this.

In scenarios when it's a full body shot and the subject is next to someone to "crop the image so that the entire person is in view and any other person is not, move then to the side of the image"

Maybe you could have a ling context for certain scenarios and have the ai/clipvision follow your preset rules for cropping.

Ps. Sd3 dataset was captioned using 50 percent cogvlm. I had no issues running on my 4090 but I forgot how many parameters this one was. I believe it may have been thudm--cogvlm-chat-hf

Usability as a website with multiple users

Over at /r/Open_Diffusion (Thread here ) a group of people are trying to build an open source dataset with the eventual goal of training a high quality model with an open source license. Since Candy Machine is gradio based, I thought it might be used for a web based tagger. So I have some questions for you:

  • Is this something you'd be OK with someone else doing?
  • Would you be open to making modifications to Candy Machine?
  • Can Candy Machine support multiple users, possibly working on the same image?
  • In what formats can Candy Machine read existing tags?

I don't want to put a pile of work on you. We have several coders who have experience with webdev who might be able to send pr's your way. Does this sound like something you'd be willing to help with?

numpy version error

Hello

I got an issue with lastest numpy version 2.0.0.

i downgrade with pip install numpy==1.26.0 and it works

KeyError

"one-piece swimsuit" seems to trigger a KeyError.

On a side note, it would be nice to have WD auto tagging as optional as it doesn't suit every dataset.

[2024-06-12 15:16:28,877] ERROR in app: Exception on /project/test/get [POST]
Traceback (most recent call last):
File "I:\Tools\candy-machine\candy-machine-main\venv\lib\site-packages\flask\app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
File "I:\Tools\candy-machine\candy-machine-main\venv\lib\site-packages\flask\app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
File "I:\Tools\candy-machine\candy-machine-main\venv\lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "I:\Tools\candy-machine\candy-machine-main\venv\lib\site-packages\flask\app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
File "I:\Tools\candy-machine\candy-machine-main\venv\lib\site-packages\flask\app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
File "I:\Tools\candy-machine\candy-machine-main\server\main.py", line 85, in get_project
project = Project(project_name)
File "I:\Tools\candy-machine\candy-machine-main\server\project.py", line 68, in init
self._load()
File "I:\Tools\candy-machine\candy-machine-main\server\project.py", line 132, in _load
self.auto_tags = self._get_filtered_auto_tags(self.project_layout)
File "I:\Tools\candy-machine\candy-machine-main\server\project.py", line 450, in _get_filtered_auto_tags
tag_info.to_dict() for tag_info in self._analyze_auto_tags()
File "I:\Tools\candy-machine\candy-machine-main\server\project.py", line 500, in _analyze_auto_tags
del tags[tag]
KeyError: 'one-piece swimsuit'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.