For this part it was a little bit difficult at the begining in terms of having data for training. So what we decided as a team was take different pictures of different racks insite of Politecnico in order to have information for this step. However, time passed and we recollected data taken from the raspberry which the pictures changed completly in terms of quality.
With the mentioned before, lets stared with the procedure that we followed:
First of all, we needed a tool in order to segment the different pictures, there were a lot, ones locally others online just like Roboflow. People from YOLOV8 suggested this tool, so that’s what we used. You go to this website: https://roboflow.com/, further you log in.

So in this part you can see all the project that you could have, we create a new one in which we upload all the pictures that we want. If you have a json or xml with the cordinates the tool automatically do the segmentation for you, otherwise you do it by hand, just like it is showed in the picture below.

After this we can apply different configurations to our dataset.

For example in the part of augmentations we could have different ones with different levels

Then after you selected all the the things that you are interested to add in your dataset. you create a new generation over that dataset. This generation could be exported in different formats and even with the key api that they give to you, you can download them from the roboflow page.

After this procedure we go into our cluster, we clone the repository of YOLOV8 in the following link: https://github.com/ultralytics/ultralytics. Then we installed all the requirements: pip install -qr requirements.txt and we ran the following code:
from ultralytics import YOLO
import yaml
import os
from roboflow import Roboflow
#Here you import your roboflow link
path = os.path.dirname(os.path.abspath(__file__))
train_folder = 'train19' #Only if transfer weights
# define number of classes based on YAML
with open(dataset.location + "/data.yaml", 'r') as stream:
num_classes = str(yaml.safe_load(stream)['nc'])
# Load a model
# model = YOLO('yolov8n.yaml') # build a new model from YAML
model = YOLO('yolov8n.yaml')
#.load(path + '/runs/detect/' + train_folder + '/weights/best.pt') # build from YAML and transfer weights
# Train the model
model.train(data= str(dataset.location) + '/data.yaml', epochs=400, imgsz=640)
When you run the code, the terminal will look like this:

Until the epochs ends or until the early stop condition of the model finished. As default it was 50 epochs of convergency, we set 400 epochs but usually the models converged at 200 epochs. In the folder runs/detect it is stored the weights with graphs of the different results over the tested dataset.