CNN for industrial parts classification in robotic automation systems.
1import tensorflow as tf
2import numpy as np
3from PIL import Image
4
5# Load model
6model = tf.keras.models.load_model('mi_modelo_ia.keras')
7
8# Preprocess image
9img = Image.open('part.jpg').resize((224, 224))
10img_array = np.array(img) / 255.0
11img_array = np.expand_dims(img_array, axis=0)
12
13# Predict
14predictions = model.predict(img_array)
15classes = ['screw', 'star', 'tee_connector']
16result = classes[np.argmax(predictions)]
17print(f"Detected: {result}")
18
19
20
21
22ROS 2 Integration
23Full robotic implementation: GitHub - UR5 Robot CNN Classifier