Art Genre Classifier
ResNet152 (ImageNet weights) fine-tuned to classify paintings into five genres: abstract, cityscape, portrait, landscape and animal painting. Try it at art.tahamukhtar.com; code and training notebook at tahamukhtar20/art-genre-classifier.
Files
art_genre_classifier.int8.onnx: the model as ONNX with dynamic int8 quantisation (58 MB). This is the file the demo serves.results.json: training history, test accuracy and confusion matrix.onnx_eval.json: the ONNX file checked against the original Keras model on the same test set.training.png: learning curves and confusion matrix.
Results
On 1,470 held-out test paintings, the original Keras model gets 87.6% right and the int8 ONNX file 87.5%.
| Genre | Test accuracy (Keras) |
|---|---|
| Portrait | 95.7% |
| Abstract | 93.0% |
| Landscape | 85.7% |
| Animal painting | 84.8% |
| Cityscape | 78.7% |
Cityscapes are most often taken for landscapes.
Training
Up to 2,000 paintings per genre from WikiArt (9,799 in total), stratified 70/15/15 split, seed 42. A new head (global average pooling, Dense 1024 with dropout, softmax) is trained first with the network frozen, then the last 30 ResNet layers are fine-tuned at a learning rate of 1e-5 with BatchNorm kept frozen. Early stopping on validation loss in both stages.
Usage
Input is a float32 tensor of shape [batch, 300, 300, 3], preprocessed like keras.applications.resnet.preprocess_input: RGB to BGR, then subtract the ImageNet means. Output is a softmax over the five classes in the order above.
import numpy as np, onnxruntime as ort
from PIL import Image
CLASSES = ["abstract", "cityscape", "portrait", "landscape", "animal-painting"]
sess = ort.InferenceSession("art_genre_classifier.int8.onnx")
img = np.asarray(Image.open("painting.jpg").convert("RGB").resize((300, 300)), dtype=np.float32)
x = (img[..., ::-1] - np.array([103.939, 116.779, 123.68], dtype=np.float32))[None]
probs = sess.run(None, {sess.get_inputs()[0].name: np.ascontiguousarray(x)})[0][0]
print(dict(zip(CLASSES, probs.round(3))))