{"slug": "surface-defect-detection-on-machined-metal-medical-parts", "title": "Surface Defect Detection on Machined Metal Medical Parts", "summary": "Roboflow released a tutorial for building an automated surface defect inspection system for machined metal medical parts using an RF-DETR Small model trained on a metal surface defect dataset, achieving 66.5% mAP@50 and 77.6% precision. The system deploys the model in a Roboflow Workflow with a Gemini 2.5 Pro block that generates inspection reports based solely on detected defects, ensuring no false findings for precision components like bone screws and fixation plates.", "body_md": "*To automate metal surface defect detection, train an RF-DETR Small model on a Roboflow Universe metal surface dataset (66.5% mAP@50, 77.6% precision) and deploy it in a Workflow that boxes each flagged region. A Gemini 2.5 Pro block then reads only those detections and writes a Defect or Defect-Free inspection report onto the image, grounded in the detector output so it cannot invent new findings, which suits precision medical parts like bone screws and fixation plates.*\n\nMachined metal components are used throughout the [medical device](https://roboflow.com/ai/medical-device-manufacturing?ref=blog.roboflow.com) industry, from surgical instruments and orthopedic implants to bone screws, fixation plates, and dental implants. These parts often require strict quality standards because even small surface defects can affect product quality, downstream manufacturing processes, and regulatory compliance.\n\nSurface defects can be introduced during machining, deburring, polishing, handling, or cleaning operations. Identifying these defects consistently through manual inspection can be challenging, particularly when manufacturing large volumes of precision components.\n\nIn this tutorial, we will build an automated surface defect inspection system using Roboflow. We will train an [ RF-DETR](https://rfdetr.roboflow.com/latest/?ref=blog.roboflow.com) model to detect visible defect regions on machined metal parts, deploy the model in\n\n[, and use](https://roboflow.com/workflows/build?ref=blog.roboflow.com)\n\n__Roboflow workflows__[to generate inspection observations based on the detected defects.](https://playground.roboflow.com/models/google/gemini-2-5-pro?ref=blog.roboflow.com)\n\n__Gemini 2.5 Pro__## Surface Defect Detection on Machined Metal Medical Parts\n\nThe system can help identify:\n\n- Visible surface defect regions on machined metal parts\n- Parts that appear defect-free\n- AI-generated inspection observations based on detected defect locations\n\nThe final output is an annotated image containing defect detections alongside AI-generated inspection observations. [Here's the workflow we'll build](https://app.roboflow.com/workflows/embed/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3b3JrZmxvd0lkIjoiNTdpY1VQbUFYN3h2SUpEU0pXbTYiLCJ3b3Jrc3BhY2VJZCI6Im5JRk5DOGRjbU5OOXZ4d29ybWpoWTdCNjdQZTIiLCJ1c2VySWQiOiJuSUZOQzhkY21OTjl2eHdvcm1qaFk3QjY3UGUyIiwiaWF0IjoxNzgxNjgzNTkzfQ.fDTz9_RYg7k243RGHVryjlduAdQ9EQWSWk_TihJiU8g?ref=blog.roboflow.com).\n\n### Step 1: Prepare the Dataset\n\nFor this tutorial, we use the Metal Surface Defect Detection [ dataset](https://universe.roboflow.com/vision-oi1kw/metal-surface-defect-detection-n7x0l?ref=blog.roboflow.com) from\n\n[. The dataset contains metal surface images captured under industrial inspection conditions and annotated with multiple defect classes representing different types of surface abnormalities.](https://universe.roboflow.com/?ref=blog.roboflow.com)\n\n__Roboflow Universe__RF-DETR is trained using the original annotations, allowing the model to learn the visual characteristics and locations of the various defect types present in the dataset.\n\nThe dataset includes metal surfaces captured under different lighting conditions, orientations, and surface textures. Defect regions vary in size, shape, and appearance, helping the model learn to identify a broad range of visible surface defects.\n\nHere are examples of the detection targets:\n\nTo begin, fork the dataset into your Roboflow workspace. Then navigate to the Train tab and select Custom Training. From the available architectures, choose RF-DETR and set the model size to Small.\n\nOnce the model architecture is selected, generate a new dataset version before starting training. Configure a 70/15/15 split for training, validation, and testing.\n\nEnable the following preprocessing steps:\n\n- Auto-orientation\n- Resize (512×512)\n\nThese preprocessing steps help normalize images captured under different inspection conditions while providing a consistent input size for RF-DETR training.\n\n### Step 2: Train the RF-DETR Model\n\nOnce training begins, RF-DETR learns to localize visible defect regions directly from the annotated examples in the dataset. Unlike a traditional classification model that only predicts whether a surface contains a defect, RF-DETR identifies the location of defect regions using bounding boxes.\n\nThis localization capability is valuable for inspection workflows because it provides visual evidence of where potential defects occur. Rather than returning a single pass/fail prediction, the model highlights the specific regions that may require further review by inspectors or quality engineers.\n\nAfter training completes, Roboflow provides evaluation metrics that help measure how accurately the model detects defect regions. These metrics allow us to determine whether the model is ready to be deployed in a workflow and used for downstream analysis with Gemini 2.5 Pro.\n\n### Step 3: Evaluate Metrics\n\nOnce training completes, review the model's detection performance on the test set. Our RF-DETR Small model achieved the following results on the surface defect detection dataset:\n\nThe model achieved 66.5% mAP@50, along with 77.6% precision, 61.6% recall, and a 67.3% F1 score. These metrics indicate that the model can identify a variety of surface defect regions across the test dataset while maintaining a relatively low false-positive rate.\n\nThe higher precision score suggests that most detected defect regions correspond to actual surface defects, reducing unnecessary inspections. The recall score indicates that some defects may still be missed, which is expected given the variety of defect types and appearances present in the dataset.\n\nThese metrics evaluate the surface defect detection model only. In the next steps, we will deploy the model in Roboflow workflows and use Gemini 2.5 Pro to generate inspection observations and classify parts as either defect or defect-free based on the detection results.\n\n### Step 4: Deploy to Workflows\n\nAfter reviewing the model metrics, deploy the RF-DETR model in Roboflow Workflows. The workflow starts with one input image of a metal part. The model detects visible surface defect regions, and a Bounding Box Visualization block renders the detections on the image.\n\nThe annotated image is then passed to Gemini 2.5 Pro. Gemini does not perform its own defect detection. Instead, it reviews the RF-DETR annotations and generates a concise inspection report. A custom Python block formats the report, and a Text Display block overlays it onto the annotated image.\n\nThe final output is a single image containing both the defect detections and the inspection summary.\n\nThe workflow uses the following sequence:\n\nTo create the workflow, open the trained model deployment options and click Try Workflows. Use the Detect and Visualize template as the starting point.\n\n### Step 5: Configure the Gemini 2.5 Pro VLM Block\n\nAdd a Google Gemini block after the Bounding Box Visualization block. Configure Gemini to receive the annotated image, not the original image. This ensures Gemini reviews the same detection evidence that appears in the final output.\n\n**Use these settings:**\n\nImage: $steps.detection_visualization.imageModel: Gemini 2.5 ProTask Type: Open Prompt\n\n**Use this prompt:**\n\n```\nYou are reviewing the output of a surface defect detection system for machined metal medical parts.\n\nThe colored annotations and bounding boxes were generated by an RF-DETR object detection model.\n\nDo not perform independent defect detection.\n\nDo not search the image for additional defects.\n\nOnly analyze the defect regions that have already been identified by the detection model and highlighted with annotations.\n\nBased solely on the provided detections:\n\n* Determine whether the part should be classified as Defect or Defect-Free.\n* If one or more defect annotations are present, classify the part as Defect.\n* If no defect annotations are present, classify the part as Defect-Free.\n\nProvide a concise inspection report using the following format:\nClassification:\nDefect or Defect-Free\nObservations:\nBriefly summarize the annotated defect regions and their approximate locations.\n\nDo not mention defects that are not annotated.\nReturn only the inspection report.\n```\n\nThis keeps the workflow grounded in the object detector output. Gemini adds a readable inspection context, but it does not invent new defect findings or override the RF-DETR detections.\n\n### Step 6: Format and Overlay the Inspection Report\n\nNext, add a custom Python block after the Gemini block. This block cleans the Gemini response so it displays cleanly on the final image.\n\n**Use this code:**\n\n``` python\ndef run(self, gemini_output):\n    text = str(gemini_output or \"\")\n    text = text.replace(\"\\r\\n\", \"\\n\").replace(\"\\r\", \"\\n\")\n    lines = []\n    previous_blank = False\n    for raw_line in text.split(\"\\n\"):\n        line = \" \".join(raw_line.strip().split())\n        if not line:\n            if not previous_blank and lines:\n                lines.append(\"\")\n            previous_blank = True\n            continue\n        lines.append(line)\n        previous_blank = False\n    cleaned = \"\\n\".join(lines).strip()\n    cleaned = cleaned.replace(\"Classification: \", \"Classification:\\n\", 1) if cleaned.startswith(\"Classification: \") else cleaned\n    cleaned = cleaned.replace(\" Observations:\", \"\\n\\nObservations:\")\n    return {\"formatted_report\": cleaned}\n```\n\nThe block preserves Gemini’s inspection report, removes extra whitespace, and keeps the Classification and Observations fields readable.\n\nFinally, add a Text Display block. Use the bounding box visualization image as the base image and the formatted report as the overlay text.\n\n### Step 7: Test the Workflow\n\nTo test the workflow, click Run in the top-right corner of Workflows and upload an image of a machined metal part. The workflow will process the image through RF-DETR, generate defect detections, and produce an inspection report based on the detected regions.\n\nThe final output is a single annotated image containing:\n\n- RF-DETR defect detections\n- A Defect or Defect-Free classification\n- Gemini-generated inspection observations\n\nSince the workflow relies on visual detections from a single image, the results should be treated as an inspection aid rather than a final quality decision. Image quality, lighting conditions, surface finish, and camera angle can all affect detection performance. Clear images with well-defined surface features generally produce the most reliable results.\n\n## Production Considerations for Medical Device Manufacturing\n\nThis tutorial demonstrates a proof-of-concept workflow using a general metal surface defect dataset. A production deployment would be trained on images collected directly from the target manufacturing process and component types.\n\nFor medical device manufacturers, this may include surgical instruments, orthopedic implants, fixation plates, bone screws, or other precision-machined metal components. Training data should capture the range of surface finishes, lighting conditions, and defect patterns encountered during normal production.\n\nThe workflow can be integrated into an inspection station using industrial cameras positioned after machining, polishing, cleaning, or finishing operations. RF-DETR can automatically identify potential defect regions, while Gemini generates structured inspection observations based on those detections.\n\nInspection records, images, and defect reports can then be stored in quality management and traceability systems for auditing, review, and process improvement. Human inspectors can focus their attention on flagged parts rather than reviewing every component manually.\n\n## Build It Faster with the Roboflow Agent\n\nIf you'd rather not add each block by hand, use [Roboflow Agent](https://app.roboflow.com/solutions/chat/new?ref=blog.roboflow.com). Instead of configuring blocks one at a time, you describe the pipeline you want in plain text and the Agent builds it for you. Here's an example:\n\n## Surface Defect Detection on Machined Metal Medical Parts Conclusion\n\nThe workflow we built can detect visible surface defects, determine whether a part should be treated as Defect or Defect-Free, and generate a concise inspection summary directly on the output image.\n\nWhile this workflow is intended as a visual inspection aid rather than a replacement for formal [quality-control](https://roboflow.com/ai/quality-control?ref=blog.roboflow.com) procedures, it demonstrates how object detection and [vision-language models](https://playground.roboflow.com/models/task/vision-language?ref=blog.roboflow.com) can be combined to support inspection workflows for machined medical components.\n\nFurther reading:\n\n**Cite this Post**\n\nUse the following entry to cite this post in your research:\n\n[Mostafa Ibrahim](/author/mostafa/). (Jun 17, 2026).\nSurface Defect Detection on Machined Metal Medical Parts. Roboflow Blog: https://blog.roboflow.com/surface-defect-detection-on-machined-metal-medical-parts/", "url": "https://wpnews.pro/news/surface-defect-detection-on-machined-metal-medical-parts", "canonical_source": "https://blog.roboflow.com/surface-defect-detection-on-machined-metal-medical-parts/", "published_at": "2026-06-17 17:10:10+00:00", "updated_at": "2026-06-17 17:27:02.143237+00:00", "lang": "en", "topics": ["computer-vision", "ai-products", "ai-tools", "ai-infrastructure", "machine-learning"], "entities": ["Roboflow", "RF-DETR", "Gemini 2.5 Pro", "Roboflow Universe", "Metal Surface Defect Detection dataset"], "alternates": {"html": "https://wpnews.pro/news/surface-defect-detection-on-machined-metal-medical-parts", "markdown": "https://wpnews.pro/news/surface-defect-detection-on-machined-metal-medical-parts.md", "text": "https://wpnews.pro/news/surface-defect-detection-on-machined-metal-medical-parts.txt", "jsonld": "https://wpnews.pro/news/surface-defect-detection-on-machined-metal-medical-parts.jsonld"}}