This folder is the "real" Python workload the .NET wrapper drives: a PyTorch/torchvision ResNet image classifier that runs on CUDA when a compatible GPU is available.
It's a plain command-line program. The rule the whole POC is built around:
If
classifier.pyruns when you type it at a terminal, it runs identically when launched by the .NETPyBridgewrapper — with stdin, stdout, stderr, and the exit code all captured and handed back to the C# caller.
- stdout = machine-readable JSON only (the result).
- stderr = human-readable progress/log lines.
- exit code:
0success ·2bad usage ·3missing dependency (e.g. no PyTorch) ·4runtime failure.
# Environment report — standard library only, so it ALWAYS runs (even with no PyTorch):
python classifier.py check
# Classify an image with a pretrained ResNet (needs torch + torchvision):
python classifier.py classify --image path/to/photo.jpg --topk 5
# No image? A synthetic test image is generated so the pipeline still runs end to end:
python classifier.py classifyFirst classify run downloads the pretrained ImageNet weights (~tens of MB) into the
torch hub cache; subsequent runs are offline.
conda env create -f environment.yml
conda activate pybridge
python classifier.py check # look for "cuda_available": trueBlackwell cards (sm_120) need CUDA 12.8+ wheels:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128
pip install pillowpip install -r requirements.txt # CPU wheels from PyPIThe PyBridge.Console app in this repo calls every one of the commands above through the
PyBridge library and prints what it captured. See the repo root README.md.