# Custom CNN Model

This function block is used to load a TensorFlow AI model for making predictions based on input images. It allows users to integrate machine learning models within their workflows easily.

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

`Image Any` An image input that is fed into the AI model for prediction.

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

`Class Index (Detected)` This output provides the index of the detected class based on the model's prediction.

`Class Name (Detected)` This output provides the name of the detected class from the model’s output.

`Detection Result (Raw Output)` This output contains the raw results from the model, useful for further analysis or debugging.

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

`Load Model` A button that, when clicked, allows the user to load a pre-trained TensorFlow or TensorFlow Lite model from their filesystem.

`Classes Text` This text area displays the list of classes that the AI model can detect, providing insight into what the model has been trained on.

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

`Support for Multiple Model Formats` This block can load both TensorFlow `.h5` models and TensorFlow Lite `.tflite` models, providing versatility in model selection.

`Detection Results Visualization` The output displays both the detected class index and name, making it easy to understand the result.

`Error Handling` Provides information about loading errors, such as invalid paths or configurations, to assist in troubleshooting.

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

1. **Load Model**: Click on the `Load Model` button to select and load your AI model. You can choose either a TensorFlow model (`*.h5`) or a TensorFlow Lite model (`*.tflite`).
2. **Input Image**: Connect an image-producing block to the `Image Any` input.
3. **Run the Block**: Execute the block to process the input image with the loaded model. The outputs will provide the predicted class index, class name, and raw output.

## 📊 Evaluation <a href="#evaluation" id="evaluation"></a>

When executed, this function block utilizes the loaded model to predict the class of the input image, returning results that reveal the predicted class index, name, and raw output data.

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

<details>

<summary>Model Compatibility</summary>

Ensure that the model you are loading is compatible with the expected input format. Models trained on certain input sizes or types may fail if the input image does not match.

</details>

<details>

<summary>Class Names Visualization</summary>

After loading the model, check the `Classes Text` area to see the classes the model can detect. This information is critical for interpreting the results accurately.

</details>

<details>

<summary>Raw Output Analysis</summary>

Examine the raw output data for deeper insights into the model's predictions. This can help in debugging the model behavior for specific inputs.

</details>

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

<details>

<summary>Model Not Loaded Error</summary>

If you encounter an error stating that the model is not loaded, verify that you've clicked the `Load Model` button and selected a valid model file.

</details>

<details>

<summary>Invalid Class Index</summary>

If the `Class Index (Detected)` output returns an unexpected value, ensure that the input image meets the model's required format and that the model has been trained to recognize that type of input.

</details>
