# Custom CNN Model

This function block lets you load a TensorFlow-based image classification model and run predictions on incoming images. It is intended for users who want to apply a custom trained convolutional neural network to classify images in a visual workflow.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`Image Any` The image that will be classified by the loaded model.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Class Index (Detected)` The numeric index of the predicted class.

`Class Name (Detected)` The human-readable class name (if the model provides class labels).

`Detection Result (Raw Output)` The raw model output or scores produced by the classifier.

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Load Model` Opens a file dialog to select and load a model file. Supported model types include standard TensorFlow models and TFLite models.

`Classes` A text area that displays the class list found inside the loaded model (if available).

## 🎨 Features <a href="#features" id="features"></a>

* Simple model import: Load a trained TensorFlow or TFLite model using a single control.
* Class label preview: The block shows class names extracted from the model so you can verify labels before running.
* Immediate inference: When a model is loaded, incoming images are classified and the results are output for downstream use.
* Outputs for automation: Both numeric index and human-readable class name are available, plus raw model outputs for advanced handling.

## ⚙️ How it runs <a href="#how-it-works" id="how-it-works"></a>

* Use the `Load Model` control to import a model file from disk.
* Once a model is loaded and verified, the block accepts images via the `Image Any` input.
* For each incoming image, the block performs inference and provides the predicted class index, optional class name, and the raw prediction values on the outputs.

## 📝 Usage Instructions <a href="#usage" id="usage"></a>

1. Click the `Load Model` button and choose your model file. Confirm that the class list appears in the `Classes` display to ensure the model is correctly loaded.
2. Connect any image source to the `Image Any` input (for example `Camera USB`, `Load Image`, or `Stream Reader`).
3. Use the block outputs to route classification results to visualization, logging, or decision logic blocks.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* Preprocess images to match your model's expected input size with `Image Resizer` or `Image Resize` before feeding them to this block. This improves prediction consistency.
* For visual verification, connect this block's image source to `Show Image` so you can preview what the model sees.
* Overlay classification results onto images using `Write Text On Image` or `Draw Result On Image` to create easy-to-understand visual outputs for operators.
* Save classification events with `Image Logger` or export numeric results to files using `CSV Export` for later analysis.
* Use `Image ROI Select` or `Image ROI` to crop to relevant areas before classification if your model expects objects at a fixed position.
* Combine with `Is None` or `Data Memory` to handle missing frames or freeze outputs when needed.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* No classes shown after loading: Ensure the model contains class label metadata. If the class list is empty, the block will still output numeric indices but no human-readable names.
* Model not loading: Verify you selected a supported model file and that the file path is accessible. If a TFLite or TensorFlow file is available, choose the appropriate file.
* Unexpected predictions: Confirm input image size, color channels, and preprocessing match what the model was trained on. Use `Image Resize`, color conversion blocks, or preprocessing steps upstream to match training conditions.
* Slow inference: Consider resizing images smaller with `Image Resizer` or using a lighter model variant before real-time deployment.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.augelab.com/function-blocks/detections-shapes/detectors/custom-cnn-model.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
