# Challenges and Solutions

This project was an iterative process of experimentation, learning, and adaptation, which involved overcoming numerous challenges related to platform compatibility, hardware limitations, app deployment, and handling large datasets. Below are the major challenges faced and the solutions implemented:

***Challenge 1: Platform Selection and Model Training***

**Description**

The project initially aimed to train the rabbit detection and counting model using TensorFlow on various platforms, including a local MacBook Pro, university virtual machines, and Google Colab. Identifying the right platform that balanced computational power, ease of use, and compatibility was a critical challenge.

**Problems Encountered**

1. **Google Colab:**
   * Version mismatches and dependency conflicts in TensorFlow prevented the model from running successfully.
   * The free tier of Google Colab often timed out during training, causing interruptions.
2. **MacBook Pro (2020, Intel Chip):**
   * Although TensorFlow could run locally, the training process took 7–8 hours due to hardware limitations (quad-core CPU and 8 GB RAM).
   * Despite successful training, the model’s performance was inadequate, likely due to computational constraints.
3. **University Virtual Machines:**
   * The SSL connection to the university virtual machines via VS Code provided better hardware but had limited availability and complex setup processes.

**Solutions**

* After experimenting with all platforms, **Google Colab Pro** emerged as the optimal choice. It provided access to powerful GPUs (Tesla T4) and extended session times, significantly speeding up training and experimentation.
* **Key Decisions:**
  * Migrating the training process entirely to Google Colab Pro for stability and speed.
  * Streamlining the training pipeline to minimize compatibility issues and reduce dependency conflicts.

**Outcome**

The adoption of Google Colab Pro resolved the computational bottlenecks and ensured smooth model training. This platform also allowed for iterative experimentation with hyperparameter tuning and different model configurations.

***

***Challenge 2: Data Management and Storage***

**Description**

The project involved processing 3–5 TB of CCTV footage from the rabbit farm. Handling such a massive dataset was a significant challenge due to storage constraints and upload/download speeds.

**Problems Encountered**

* Local storage on the MacBook Pro and external drives was insufficient for storing and processing the entire dataset.
* Uploading videos to Google Colab or the university virtual machine required extensive time, often disrupting the workflow.

**Solutions**

* The **university’s Seafile** storage system was utilized for managing large video files. Videos were uploaded and downloaded in smaller batches to facilitate annotation and processing.
* Video frames were extracted and processed incrementally to optimize storage usage and reduce computational overhead.

<figure><img src="https://843131242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8U1yBUBlixXNqT1lQ16c%2Fuploads%2FgJStmzpzre0gRRPKU8Qc%2FScreenshot%202025-01-14%20at%2012.34.35%20AM.png?alt=media&#x26;token=5313cf45-27be-47a2-82b7-d66a9d219f52" alt="" width="375"><figcaption><p>Seafile cloud storage for videos</p></figcaption></figure>

**Outcome**

Although managing large datasets remained a logistical challenge, Seafile and incremental processing provided a workable solution for annotation, training, and testing.

***

***Challenge 3: App Development and Deployment***

**Description**

Developing a user-friendly app for rabbit detection and counting was a critical deliverable of this project. Building both macOS and Windows apps presented unique challenges.

**Problems Encountered**

1. **MacBook Pro:**
   * Successfully built the macOS `.dmg` app using PyInstaller, but it required significant resources and time due to the model’s size and complexity.
   * The app ran slower when launched from the GUI compared to running directly from the terminal, likely due to hardware constraints.
2. **Windows App:**
   * As the customer required a Windows-compatible app, building the `.exe` file on a MacBook was infeasible.
   * Running a Windows virtual machine (VM) on macOS through **Microsoft Azure** was extremely slow and resource-intensive.
   * Testing the app on the Windows VM was impractical due to performance issues.
3. **Final Testing:**
   * To ensure the app’s usability, it was tested on a friend’s custom-built gaming PC, which provided the necessary hardware for smooth performance.

**Solutions**

* **Azure Windows VM:** A Windows 11 virtual machine was configured on Azure for building the `.exe` file. Although slow, it enabled successful app creation.
* **Cross-Platform Testing:** The app was tested on both macOS and a gaming PC to ensure compatibility and performance.
* **Recommendation to Users:** Customers were advised to run the app from the terminal (command line) for better performance.

**Outcome**

Both macOS and Windows apps were successfully delivered, with a functional `.dmg` file for macOS and a `.exe` file for Windows. A screenshot of the Azure Windows VM setup is included below.

<figure><img src="https://843131242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8U1yBUBlixXNqT1lQ16c%2Fuploads%2FaG5YTqV4v7rUsPqOjaRj%2FScreenshot%202025-01-14%20at%2012.37.02%20AM.png?alt=media&#x26;token=ca90eeff-91af-48a4-aca5-23173a8af042" alt="" width="563"><figcaption><p>Windows VM in Mac connected</p></figcaption></figure>

***

***Challenge 4: Building the Windows App***

**Description**

Building the Windows `.exe` app presented a unique set of challenges:

* Installing dependencies (e.g., TensorFlow) in the Windows environment required troubleshooting multiple DLL errors.
* Limited hardware on the Azure VM resulted in long build times.

**Solution**

* Dependency conflicts were resolved by installing specific Visual C++ Redistributables and using Miniconda to manage the Python environment.
* The app was built successfully using PyInstaller, with paths to models and other resources explicitly defined.

***

***Challenge 5: Iterative Experimentation***

**Description**

The project evolved through a "learn-and-grow" approach, with early experiments using PyTorch and YOLOv5 before transitioning to TensorFlow and TFLite for better compatibility with mobile and edge devices.

**Problems Encountered**

* Early PyTorch implementations lacked performance consistency for small-object detection in dynamic farm environments.
* Transitioning to TensorFlow required re-annotation of datasets and adapting the pipeline for TFLite compatibility.

**Solution**

* The switch to TensorFlow and TFLite improved performance on low-power devices while maintaining accuracy.
* Extensive experiments with hyperparameter tuning, data augmentation, and model pruning were conducted to enhance detection robustness.

***

**Summary of Challenges and Solutions**

| Challenge                 | Problem                                                             | Solution                                                                       | Outcome                                                                  |
| ------------------------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
| Platform Selection        | Compatibility and computational limitations across platforms.       | Google Colab Pro was adopted for its powerful GPUs and extended session times. | Faster training and iterative experimentation.                           |
| Data Management           | Handling 3–5 TB of video footage.                                   | Utilized university Seafile and incremental frame processing.                  | Managed storage effectively for training and testing.                    |
| App Development           | Building cross-platform apps and testing performance.               |                                                                                | Delivered functional apps for both platforms.                            |
| Building the Windows App  | Dependency and DLL errors during Windows app creation.              | Resolved conflicts with Visual C++ Redistributables and Miniconda.             | Successfully built the Windows app.                                      |
| Iterative Experimentation | Switching frameworks (PyTorch to TensorFlow) and adapting datasets. | Focused on TensorFlow and TFLite for better performance and compatibility.     | Improved detection accuracy and robustness in dynamic farm environments. |

By addressing these challenges, the project achieved a fully functional rabbit detection and counting system that is ready for deployment and further optimization.
