Reusable PyTorch modules for pathology-focused feature gating and guided token reweighting.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pfd_gste-0.1.0.tar.gz.
File metadata
- Download URL: pfd_gste-0.1.0.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35746248cc068f1f6696850cb33bf606050e130590c503d08445454703aa5e7f
|
|
| MD5 |
a65a9c691c794c2d473643f25234e70d
|
|
| BLAKE2b-256 |
3cd81fa5e5f0dbd27c20bcfb43724ce6dd724e220ca20831d8d6eb78f486c5e1
|
Provenance
The following attestation bundles were made for pfd_gste-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on AnnyaB/HybridResNet50V2-RViT
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pfd_gste-0.1.0.tar.gz -
Subject digest:
35746248cc068f1f6696850cb33bf606050e130590c503d08445454703aa5e7f - Sigstore transparency entry: 1752877232
- Sigstore integration time:
-
Permalink:
AnnyaB/HybridResNet50V2-RViT@473a8e0dd419dba9a88dd295bf9adb7c0c793a82 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/AnnyaB
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@473a8e0dd419dba9a88dd295bf9adb7c0c793a82 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pfd_gste-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pfd_gste-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa0a3f4b860a74b850881a3e3d165803ea921cefa12f674f4034b73c0f65cb03
|
|
| MD5 |
c941c37de63fd244ef6361dd81627e33
|
|
| BLAKE2b-256 |
3c4f46fba3d62fccf84ae9e298f1ea2f260d456fa3830c3bd31365cdb56f4302
|
Provenance
The following attestation bundles were made for pfd_gste-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on AnnyaB/HybridResNet50V2-RViT
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pfd_gste-0.1.0-py3-none-any.whl -
Subject digest:
fa0a3f4b860a74b850881a3e3d165803ea921cefa12f674f4034b73c0f65cb03 - Sigstore transparency entry: 1752877299
- Sigstore integration time:
-
Permalink:
AnnyaB/HybridResNet50V2-RViT@473a8e0dd419dba9a88dd295bf9adb7c0c793a82 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/AnnyaB
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@473a8e0dd419dba9a88dd295bf9adb7c0c793a82 -
Trigger Event:
workflow_dispatch
-
Statement type: