日本語ページ   ▶AI art top   ▶AI art blog   ▶Image top  

🤖🖼 AI Art Blog 🅰🅸 🅰🆁🆃

A blog related to original AI artworks. I make AI artworks using coined words and emoji as prompts.


Tried Classifying AI Art with ChatGPT

2024-10-14 14:00

At the beginning of this project, I classified artworks based on the subject matter depicted in the images. However, as the number of artworks and the amount of drawings increased, I could no longer continue this approach. Yet, classifying images by their content or type is important, especially for viewers. So, I decided to try letting ChatGPT handle the classification.

Using ChatGPT-4o, I provided images for it to analyze and select one or multiple categories from a predefined set. I gave it the following categories (in Japanese) and had it classify the higher-ranked images (currently 5617 images), and links to these images are included here.

All these artworks can be accessed through "★Classification by ChatGPT".

Using the ChatGPT-4o API, I showed the system a reduced version of the images available on this site. It took about 2 to 5 seconds in real time to analyze each image. The categories classified by ChatGPT were extracted from the response log and added to the image database. During extraction, abbreviations like Hu, An, Pa, etc., were used as keys for the categories. Since multiple categories could be selected, more than half of the images were classified as abstract. I am also considering ways to further classify these and plan to try them soon.

Finally, for reference, here is the main part of the program.

from openai import OpenAI
import base64, requests, pprint, time, sys

MODEL = "gpt-4o"

Client = OpenAI(api_key = ʼsk-proj-xxxxxxxxxxxxxxxxʼ)

def run(ImageIDList):
    for id in ImageIDList:
        base64_image = encode_image(f"https://dasyn.com/aiart/image/{id}e.jpg")

        print(fʼ# {id}ʼ)
        question = (
            f"Which of the following categories does this image ({id}) belong to? "
            "It may fall under multiple categories or none at all: "
            "Hu: Artwork of a person’s full body or half-body, An: Artwork of a full body "
	    "or half-body of an animal, Pa: Artwork of only the face or eyes of a person or animal, "
            "Pl: Artwork of growing or arranged plants, Na: Artwork of natural scenery, "
	    "AS: Artwork of artificial scenery, Ar: Artwork of artificial objects other than scenery, "
	    "Ab: Abstract art that does not depict people, animals, landscapes, or tangible objects."
        )
        initial_time = time.time()
        response = Client.chat.completions.create(
            model = MODEL,
            messages = [
                {"role": "system", "content":
                 "You are an expert in art interpretation. "
		 "Please tell us about the AI art pieces I have created."},
                {"role": "user", "content": [
                    {"type": "text", "text": question},
                    {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{base64_image}"}}
                ]}
            ],
            temperature = 0.0,
        )
        print(fʼ# {time.time() - initial_time}ʼ)

        content = response.choices[0].message.content

        pprint.pprint({
            "id": id,
            "question": question,
            "reply": content.replace(ʼ。ʼ, ʼ.\nʼ).replace(ʼ、ʼ, ʼ,ʼ),
        })

Dasyn.com デイシン
Created: 2024-10-14 14:00   Edited: 2024-10-16