0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

アート作品をAIで分類してみよう【Google Colab + Keras】

Posted at

はじめに

「このアート作品、AIはどんなふうに分類するんだろう?」

そんな疑問を持ったことはありませんか?
今回は、Google ColabとKerasの事前学習済みモデル(ImageNet)を使って、自分でアップロードした画像をAIに分類させるプロジェクトを紹介します。

アート作品や写真をアップロードするだけで、AIがそれに最も近いカテゴリを予測してくれます。
絵画・彫刻・風景・静物画など、さまざまな画像で遊びながら学べます!


使用する技術

ライブラリ 用途
tensorflow.keras モデルのロードと画像前処理
matplotlib 画像の表示
google.colab.files ファイルアップロード

コード全体

from google.colab import files
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.vgg16 import VGG16, preprocess_input, decode_predictions
import numpy as np
import matplotlib.pyplot as plt

# 事前学習済みのVGG16モデルをロード
model = VGG16(weights='imagenet')

# ファイルアップロード(画像ファイルを選んでアップロード)
uploaded = files.upload()
filename = list(uploaded.keys())[0]  # 最初のファイル名を取得

# 読み込みと前処理
img = image.load_img(filename, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

# 予測実行
preds = model.predict(x)
top_preds = decode_predictions(preds, top=5)[0]

# 結果の表示
plt.figure(figsize=(6, 6))
plt.imshow(img)
plt.axis("off")
plt.title("Uploaded Art Image", fontsize=16)
plt.show()

print("🎨 Prediction Results:")
for label, name, score in top_preds:
    print(f"{name}: {round(score * 100, 2)}%")

実行方法(Google Colab)

  1. 上記のコードをColabに貼り付けて実行
  2. 表示された「ファイル選択」ボタンから画像をアップロード
  3. 数秒後、AIによる分類結果とアップロード画像が表示されます

結果

🎨 Prediction Results:
paintbrush: 45.6%
palace: 22.3%
altar: 12.7%
theater_curtain: 8.1%
mural: 6.3%
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?