Example #1
0
def create_dataset():
    print('criando dataset')
    data = ImageClassifierDataLoader.from_folder('./images_dataset')
    train_data, rest_data = data.split(0.8)
    validation_data, test_data = rest_data.split(0.5)
    model = image_classifier.create(train_data,
                                    validation_data=validation_data,
                                    epochs=10)
    model.summary()
    model.export(export_dir='model/', export_format=ExportFormat.LABEL)
    model.export(export_dir='model/')
Example #2
0
Tensorflow Lite Model Maker ile Uygulama için Hazır Edilmesi (Mobil Kullanım için)

pip install tflite-model-maker

import tensorflow as tf
assert tf.__version__.startswith('2')

from tflite_model_maker import configs
from tflite_model_maker import ExportFormat
from tflite_model_maker import image_classifier
from tflite_model_maker import ImageClassifierDataLoader
from tflite_model_maker import model_spec

import matplotlib.pyplot as plt

# Eğitim, Değerlendirme ve Test Verilerinin Yüklenmesi 
training_data = ImageClassifierDataLoader.from_folder('/content/drive/MyDrive/onayli_onaysiz_512x512/training/')
validation_data = ImageClassifierDataLoader.from_folder('/content/drive/MyDrive/onayli_onaysiz_512x512/validation/')
test_data = ImageClassifierDataLoader.from_folder('/content/drive/MyDrive/onayli_onaysiz_512x512/test/')
print(len(validation_data))
print(len(test_data))

# Modelin Eğitilmesi
model = image_classifier.create(training_data, validation_data=validation_data, epochs=10)

# Modelin Test Verileriye Onaylanması
loss, accuracy = model.evaluate(test_data)

# Tensorflow Lite Modelin Yüklenmesi ve bu Dosya Android Studio tarafından kullanılabilecektir
model.export(export_dir='.')
Example #3
0
    seed=12,
    image_size=(imgHeight, imgWidth),
    batch_size=batchSize)

# Save labels
classNames = trainDataset.class_names
print("Classes names:%s" % classNames)
np.savetxt(labelsPath, classNames, '%s', delimiter='\n')
print("Control class names:")
for s in classNames:
    print(s, end=', ')
print()
print("Control labels save to path: %s" % labelsPath)

# Load data
data = ImageClassifierDataLoader.from_folder(path)
trainData, testData = data.split(0.62)
trainData = data

# Create model
model = image_classifier.create(trainDataset)
model.summary()

# Evaluate the model
loss, acc = model.evaluate(testData)
print("Model accuracy: %.4f" % acc)
print("Model loss: %.4f" % loss)

# Export model
model.export(modelPath)
Example #4
0
# Tensorflow initialization
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
    try:
        # Currently, memory growth needs to be the same across GPUs
        for gpu in gpus:
            tf.config.experimental.set_memory_growth(gpu, True)
        logical_gpus = tf.config.experimental.list_logical_devices('GPU')
        print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
    except RuntimeError as e:
        # Memory growth must be set before GPUs have been initialized
        print(e)

# Initialize dataset
folder_name = r"trash_dataset_resized"
data = ImageClassifierDataLoader.from_folder(folder_name)

# Create train, validation, test splits
train_data, rest_data = data.split(0.7)
validation_data, test_data = rest_data.split(0.5)

# Plot 25 elements from dataset
plt.figure(figsize=(10, 10))
for i, (image, label) in enumerate(data.gen_dataset().unbatch().take(25)):
    plt.subplot(5, 5, i + 1)
    plt.xticks([])
    plt.yticks([])
    plt.grid(False)
    plt.imshow(image.numpy(), cmap=plt.cm.gray)
    plt.xlabel(data.index_to_label[label.numpy()])
plt.savefig("dataset_sample.png")