Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
Jose Luis Espí
Created July 27, 2024

Tile Defects Inspection

Automatic inspection system for printing defects in ceramic tiles, using YOLOv8 model trained with tiles images

13
Tile Defects Inspection

Things used in this project

Hardware components

Minisforum Venus UM790 Pro with AMD Ryzen™ 9
Minisforum Venus UM790 Pro with AMD Ryzen™ 9
×1

Software apps and online services

AMD ROCm™ Software
AMD ROCm™ Software

Story

Read more

Custom parts and enclosures

Best weights

It's the weights result from training the model

Code

Pyhton code to train the model

Python
It's a Pyhthon3 code used to train a Yolov8 model with a tiles dataset
import ultralytics
ultralytics.checks()
from ultralytics import YOLO

# Load a model
model = YOLO('yolov8n.yaml')  # build a new model from scratch
model = YOLO('yolov8n.pt')  # load a pretrained model (recommended for training)

# Use the model
results = model.train(data='data.yaml', epochs=100)  # train the model
results = model.val()  # evaluate model performance on the validation set

Python code to test model

Python
It's a Python code to test the trained model with a set of images from a folder
from ultralytics import YOLO
import cv2
import os
model = YOLO("yolov8n.yaml")
model = YOLO("best.pt")

# Directorio con las imgenes
directory = 'test/images'

for filename in os.listdir(directory):
    if filename.endswith('.jpg') or filename.endswith('.png'):  # Filtrar por tipo de archivo
        image_path = os.path.join(directory, filename)
        image = cv2.imread(image_path)
        # Realizar la deteccin de objetos
        results = model(image)
        print(f'Imagen: {image_path}')

        # Inicializar la variable de deteccin
        object_found = 0
        
        # Verificar si se ha encontrado algn objeto
        for result in results:
            if len(result.boxes) > 0:  # Si hay alguna caja de deteccin
                object_found = 1
                break
        # Iterar sobre los resultados y mostrar cada uno
        if (object_found == 1):
            for result in results:
                result.show()
            break

Credits

Jose Luis Espí
1 project • 1 follower
Thanks to Roboflow and Ultralytics.

Comments