PFD–GSTE
Reusable PyTorch modules for pathology-focused feature gating and guided token reweighting in CNN, Transformer and hybrid image classifiers.
PFD–GSTE was developed as part of the research project Mitigating Shortcut Learning in Brain Tumour MRI Classification. This package isolates the reusable guidance components from the complete experimental repository.
Included modules
PathologyFocusedGatelearns a soft spatial guidance mask from a CNN feature map.FeatureTokenGuidanceapplies a spatial mask to CNN-derived transformer tokens.PatchEmbed2dprovides lightweight two-dimensional patch embedding.PatchTokenGuidanceguides image patch tokens and can optionally reduce the token grid.PFDGSTEVariantAcombines pathology-focused gating with feature-token guidance.PFDGSTEVariantBcombines pathology-focused gating with image patch-token guidance.enable_mc_dropoutenables dropout layers during inference.mc_dropout_predictperforms repeated stochastic inference for MC-dropout estimation.
Installation
After publication to PyPI:
pip install pfd-gste
Basic import
from pfd_gste import (
PathologyFocusedGate,
PFDGSTEVariantA,
PFDGSTEVariantB,
mc_dropout_predict,
)
Variant A
Variant A is intended for models whose transformer tokens are produced from a CNN feature map.
import torch
from pfd_gste import PFDGSTEVariantA
guidance = PFDGSTEVariantA(
in_channels=2048,
embed_dim=128,
)
features = torch.randn(2, 2048, 7, 7)
tokens, mask, alpha = guidance(features)
print(tokens.shape)
print(mask.shape)
print(alpha.shape)
Variant B
Variant B combines a CNN-derived pathology mask with image patch tokens.
import torch
from pfd_gste import PFDGSTEVariantB
guidance = PFDGSTEVariantB(
in_channels=2048,
embed_dim=128,
image_channels=3,
patch_size=16,
min_side=7,
max_shrink=0.50,
)
images = torch.randn(2, 3, 224, 224)
features = torch.randn(2, 2048, 7, 7)
gated_features, tokens, mask, alpha, token_hw = guidance(
images,
features,
shrink=True,
)
print(gated_features.shape)
print(tokens.shape)
print(mask.shape)
print(alpha.shape)
print(token_hw)
Complete research repository
The complete repository contains the preprocessing pipeline, four matched model variants, training and held-out evaluation workflows, explainability scripts, recorded results, trained checkpoints and local Flask prototype:
https://github.com/AnnyaB/HybridResNet50V2-RViT
The Python package contains only the reusable PFD–GSTE guidance components. It does not contain datasets, trained checkpoints, complete classifiers, experimental results or clinical software.
Research-use notice
This package is provided for research and educational use only. It is not a certified medical device and must not be used for clinical diagnosis, patient management or treatment decisions.
Licence
MIT License.
Metadata
Release files for pfd-gste 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pfd_gste-0.1.0.tar.gz | 20.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pfd_gste-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.1 kB
Release files / pfd_gste-0.1.0.tar.gz
| Download URL | pfd_gste-0.1.0.tar.gz |
|---|---|
| Size | 20.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35746248cc068f1f6696850cb33bf606050e130590c503d08445454703aa5e7f
|
|
BLAKE2b-256 checksum How to use checksums |
3cd81fa5e5f0dbd27c20bcfb43724ce6dd724e220ca20831d8d6eb78f486c5e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.
Transparency logRelease files / pfd_gste-0.1.0-py3-none-any.whl
| Download URL | pfd_gste-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fa0a3f4b860a74b850881a3e3d165803ea921cefa12f674f4034b73c0f65cb03
|
|
BLAKE2b-256 checksum How to use checksums |
3c4f46fba3d62fccf84ae9e298f1ea2f260d456fa3830c3bd31365cdb56f4302
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.
Transparency log