Open ImoutoChan opened 1 year ago
The models are under releases. Technically that should work, but I remember that there were some issues. You will have to try and see if you can get it working I fear.
I have created a Dockerfile with and without the model: https://github.com/kamuridesu/DeepDanbooru Tags are:
kamuri/deepdanbooru:nomodel
for the image without a modelkamuri/deepdanbooru:latest
for image with modelAlthough it does not have any API but isn't so hard, I may create one later.
Also, check https://github.com/kamuridesu/deepdanbooryu, a project using events and Docker to create a fully scalable backend if you're interested.
Thank you, I'm definitely waiting for a docker image with API.
If anyone else is interested in using DeepDanbooru through docker you can:
linux
docker run -v /images:/app/images kamuri/deepdanbooru:latest evaluate /app/images/1.png --project-path /app/model
windows
docker run -v //c/images:/app/images kamuri/deepdanbooru:latest evaluate /app/images/1.png --project-path /app/model
for the image in C:\images\1.png
or in /images/1.png
A simple Web API implementation for evaluate_image
:
import os
import deepdanbooru
from io import BytesIO
from deepdanbooru.commands import evaluate_image
from flask import Flask, request, render_template
PROJECT_PATH = os.path.abspath("model")
print("Loading model")
MODEL = deepdanbooru.project.load_model_from_project(
PROJECT_PATH, compile_model=False
)
print("Loading tags")
TAGS = deepdanbooru.project.load_tags_from_project(PROJECT_PATH)
app = Flask("deepdanbooru", template_folder=os.path.abspath("templates"))
@app.route("/")
def index():
return render_template("index.html")
@app.route("/upload", methods=["POST"])
async def upload():
if "file" not in request.files:
return "No file uploaded!"
file = request.files["file"]
result = evaluate_image(BytesIO(file.stream.read()), MODEL, TAGS, 0.5)
results = {}
for tag, score in result:
results[tag] = float(f"{score:05.3f}")
return results
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port="8080")
The model is stored in a subdir called model
, placed in the same folder as the script, just extract the .zip in releases to the folder. It also has a templates/index.html
file to test the upload:
<!DOCTYPE html>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<h1>Upload a File</h1>
<form action="/upload" method="POST" enctype="multipart/form-data">
<input type="file" name="file" accept="*">
<input type="submit" value="Upload">
</form>
</body>
</html>
Is there any docker image with some kind of HTTP API (like your demo)?
If there is none I would like to make one, but I have zero knowledge in Python development, maybe you have some tips? I also don't see the trained model, only instructions on how to make my own. Can I just download it from somewhere?
The way I see it:
Am I right?