Skip to main content

Dual-model detection for YOLO backbones

Project description

NeuronSwitch

Dual-model detection for YOLO backbones.

Installation

Install my-project with pip

  pip install neuronswitch

requires ultralytics==8.3.164, ultralytics-thop==2.0.18, torch==2.9.1, torchvision==0.24.1

License

Apache License 2.0

Screenshots

Idea

Documentation

# IMPORTS
from neuronswitch.farida_DualYOLO import DualYOLO
from neuronswitch.farida_DualConv import farida_convert_backbone_to_dual,farida_activate_weight_set, run_dual_inference

# ✔ Converting backbone to Dual Mode
converted_backbone = farida_convert_backbone_to_dual(model_one_yolo.model, model_two_yolo.model)
dual_model = DualYOLO(converted_backbone, model_one_head, model_two_head)
dual_yolo = YOLO()
dual_yolo.model = dual_model

# Set Model, if mode = 1 then Model A else if model =2 then Model B
dual_model.mode = 1
farida_activate_weight_set(dual_model, 1)

# INFERENCE
results = run_dual_inference(dual_yolo , 1, model_one_yolo.names, "test.jpeg", conf=0.25)
        

# POST PROCESSING        
results[0].show()
# Print clean detections to console
for box in results[0].boxes:
    print(f"✅ Verified Detection: {model_one_yolo.names[int(box.cls[0])]}")

Usage/Examples

from ultralytics import YOLO
from neuronswitch.farida_DualYOLO import DualYOLO
from neuronswitch.farida_DualConv import farida_convert_backbone_to_dual,farida_activate_weight_set, run_dual_inference

# --- MAIN ---

if __name__ == "__main__":
    model_one_path = "yolov8n.pt"
    model_two_path = "catdog.pt"

    model_one_yolo = YOLO(model_one_path)
    model_two_yolo = YOLO(model_two_path)

    model_one_head = model_one_yolo.model.model[-1]
    model_two_head = model_two_yolo.model.model[-1]

    print("✔ Converting backbone to Dual Mode...")
    converted_backbone = farida_convert_backbone_to_dual(model_one_yolo.model, model_two_yolo.model)
    dual_model = DualYOLO(converted_backbone, model_one_head, model_two_head)

    dual_yolo = YOLO()
    dual_yolo.model = dual_model

    # --- MODEL 1 OUTPUT  MODE 1  ---
    print("\n🟢 MODE 1: MODEL 1 OUTPUT")
    try:
        dual_model.mode = 1
        farida_activate_weight_set(dual_model, 1)
        results = run_dual_inference(dual_yolo , 1, model_one_yolo.names, "test.jpeg", conf=0.25)
        results[0].show()
                
        # Print clean detections to console
        for box in results[0].boxes:
            print(f"✅ Verified Detection: {model_one_yolo.names[int(box.cls[0])]}")


    except Exception as e:
        print(f"Error in Human Mode: {e}")

    # --- MODEL 2 OUTPUT MODE 2 ---
    print("\n🟣 MODE 2: MODEL 2 OUTPUT")
    try:
        dual_model.mode = 2
        farida_activate_weight_set(dual_model, 2)
        results = run_dual_inference(dual_yolo , 2, model_two_yolo.names, "catdog.jpeg", conf=0.25)
        results[0].show()
                
        # Print clean detections to console
        for box in results[0].boxes:
            print(f"✅ Verified Detection: {model_two_yolo.names[int(box.cls[0])]}")

    except Exception as e:
        print(f"Error in Human Mode: {e}")



    print("\n✔ DONE.")

🚀 About Me

SHREYAS POTDAR (shreyasapp9@gmail.com)

I'm a developer addressing real world problem

my work:

NeuronSwitch : https://pypi.org/project/neuronswitch/

https://github.com/SHREYAS1188/neuronswitch

https://github.com/SHREYAS1188/neuronswitchpublic

myvectors : https://pypi.org/project/myvectors/

https://github.com/SHREYAS1188/vector_python_package

AI App using Pose estimation : https://play.google.com/store/apps/details?id=com.shreyas.take3_mod2&pcampaignid=web_share

Acknowledgements

I Would Like to Thank Everyone

Feedback

If you have any feedback, please reach out to us at shreyasapp9@gmail.com

Or raise an issue at github. https://github.com/SHREYAS1188/neuronswitchpublic/issues

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neuronswitch-2.0.4.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neuronswitch-2.0.4-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file neuronswitch-2.0.4.tar.gz.

File metadata

  • Download URL: neuronswitch-2.0.4.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for neuronswitch-2.0.4.tar.gz
Algorithm Hash digest
SHA256 9d420e7ae9bf893bc5a16544d58bdea6db5868f479d0fb78b7cf043230316220
MD5 179e3e4e8b09a5747e727c69afb80c8c
BLAKE2b-256 21f2833818c7b8c05ee1d836131ab1541a5e8bd1241b56f057e0251966f06785

See more details on using hashes here.

File details

Details for the file neuronswitch-2.0.4-py3-none-any.whl.

File metadata

  • Download URL: neuronswitch-2.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for neuronswitch-2.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 89f7237c513740d39408a489a20dbddaf46f773c8c30f43551987046f493b989
MD5 10ba7035f448b77e34c1705fdf3f264b
BLAKE2b-256 430a4af675adf49341982c05293e9464dab38d6686f4eabe03e9fef2f5ee6bcc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page