image_output_1.png
from sklearn.preprocessing import MultiLabelBinarizer

from tensorflow.keras.layers import Input, Dense

from tensorflow.keras.models import Model

from vit_keras import vit, utils

import cv2 as cv

import numpy as np

import os

import re

X = []
Y = []
input_shape = (96, 96, 3)
path_to_subset = f'../input/apparel-images-dataset/'
for folder in os.listdir(path_to_subset):
    for image in os.listdir(os.path.join(path_to_subset, folder)):
        path_to_image = os.path.join(path_to_subset, folder, image)
        image = cv.imread(path_to_image)
        image = cv.resize(image, (input_shape[1], input_shape[0]))
        label = re.findall('\\w+\\_\\w+', path_to_image)[0].split('_')
        X.append(image)
        Y.append(label)
X = np.array(X) / 255.0
Y = np.array(Y)
mlb = MultiLabelBinarizer()
Y = mlb.fit_transform(Y)

input_shape = (96, 96, 3)
num_classes = Y.shape[1]
vit_model = vit.vit_b16(image_size=input_shape[0], activation='softmax', pretrained=True, include_top=False, pretrained_top=False, classes=num_classes, weights='imagenet21k')
for layer in vit_model.layers:
    layer.trainable = False
output_layer = Dense(num_classes, activation='sigmoid')(vit_model.output)
model = Model(inputs=vit_model.input, outputs=output_layer)