This is my data. it has 7 images:
I using autokeras
to training:
import tensorflow as tf
import numpy as np
import autokeras as ak
from tensorflow.keras.preprocessing import image
BATCH_SIZE = 32
IMG_HEIGHT = 224
IMG_WIDTH = 224
train_data_dir = "E:\\DemoTensorflow\\NhanDienDoiTuong\\Data\\Traintest"
def preprocess(img):
img = image.array_to_img(img, scale=False)
img = img.resize((IMG_WIDTH, IMG_HEIGHT))
img = image.img_to_array(img)
return img / 255.0
image_generator = tf.keras.preprocessing.image.ImageDataGenerator(
rescale=1.0 / 255,
horizontal_flip=True,
validation_split=0.2,
preprocessing_function=preprocess,
)
train_generator = image_generator.flow_from_directory(
directory=train_data_dir,
batch_size=BATCH_SIZE,
shuffle=True,
target_size=(IMG_HEIGHT, IMG_WIDTH),
subset="training",
)
val_generator = image_generator.flow_from_directory(
directory=train_data_dir,
batch_size=BATCH_SIZE,
shuffle=True,
# class_mode="categorical",
target_size=(IMG_HEIGHT, IMG_WIDTH),
subset="validation",
)
def callable_iterator(generator):
for img_batch, targets_batch in generator:
yield img_batch, targets_batch
train_dataset = tf.data.Dataset.from_generator(
lambda: callable_iterator(train_generator),
output_types=(tf.float32, tf.int8),
output_shapes=(
tf.TensorShape([None, 224, 224, 3]),
tf.TensorShape([None, 2]),
),
)
val_dataset = tf.data.Dataset.from_generator(lambda: callable_iterator(val_generator),output_types=(tf.float32, tf.float32))
clf = ak.ImageClassifier(max_trials=10)
clf.fit(train_dataset, epochs=10)
print(clf.evaluate(val_dataset))
Result: It can't finish when execute:
It hang at this command very long: StreamExecutor device (0): Host, Default Version
Why can't finish my training?
My OS is Win7, python 3.8, tensorflow 2.3, autokeras 1.0.8