{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":91249,"databundleVersionId":11294684,"sourceType":"competition"}],"dockerImageVersionId":30918,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# BYU Locating Flagellar Motors\n\n## Solution Overview\n\nThis is the index notebook for my solution to the BYU Locating Bacterial Flagellar Motors 2025 Kaggle competition. I used a 2D YOLOv8-based approach by training a bounding box model on the slices in the dataset that contained motors. To submit the model, I had it iterate over every slice in each tomogram of the test dataset and had it select the point of highest confidence as the annotation. \n\n### Notebook Series:\n\n1. **[Parse Data](https://www.kaggle.com/code/andrewjdarley/parse-data)**\n   - Extracts 2D slices with motors\n   - Normalizes slice intensity using percentile-based contrast enhancement (standard across all work here)\n   - Converts annotations to YOLO format\n   - Creates train/validation splits at the tomogram level. ie creates an 80/20 split of motors, not tomograms\n\n2. **[Visualize Data](https://www.kaggle.com/code/andrewjdarley/visualize-data)**\n   - Visualizes random training samples with annotations\n   - Confirms proper bounding box placement\n\n3. **[Train YOLO](https://www.kaggle.com/code/andrewjdarley/train-yolo)**\n   - Fine tunes YOLOv8\n   - Monitors training/validation losses with early stopping, dfl loss is all that matters for this application\n   - Validates model performance on val slices\n\n4. **[Submission Notebook](https://www.kaggle.com/code/andrewjdarley/submission-notebook)**\n   - Processes test tomograms with GPU optimization\n   - Implements 3D non-maximum suppression for detection clustering\n   - Generates the final submission CSV\n   - Runs in an offline environment using pre-installed dependencies (This notebook was a lifesaver: https://www.kaggle.com/code/itsuki9180/ultralytics-for-offline-install)\n\nA complete notebook combining all the above can be found [here](https://www.kaggle.com/code/sharifi76/eda-visualization-yolov8)\n\n## Solution Approach\n\nThis solution treats the bacterial flagellar motor detection problem as a 2D object detection task with 3D post-processing. Key aspects include:\n\n- **Data Preprocessing**: We extract multiple slices around each annotated motor to capture 3D context, normalize intensity for better contrast, and convert annotations to YOLO format.\n\n- **Model Architecture**: Using YOLOv8 with transfer learning from pre-trained weights to accelerate training on the specialized dataset.\n\n- **Inference Strategy**: The inference pipeline processes test tomograms in batches with GPU optimization, detecting motors in 2D slices and then merges nearby motors.\n\n## Requirements\n\n- Ultralytics YOLOv8 package through offline install\n\n## Competition Details\n\nThe BYU Locating Bacterial Flagellar Motors 2025 challenge involves locating flagellar motors in CryoET bacteria tomograms.","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}}]}