mednet.config.data.tbx11k.datamodule#
Module Attributes
Key to search for in the configuration file for the root directory of this database. |
|
Type of objects in our JSON representation for this database. |
Functions
|
Return a database split for the Montgomery database. |
Classes
|
Location of radiological findings. |
|
A collection of bounding boxes. |
|
TBX11k dataset for TB detection. |
A specialized raw-data-loader for the TBX11k dataset. |
- mednet.config.data.tbx11k.datamodule.CONFIGURATION_KEY_DATADIR = 'datadir.tbx11k'#
Key to search for in the configuration file for the root directory of this database.
- class mednet.config.data.tbx11k.datamodule.BoundingBox(label, xmin, ymin, width, height)[source]#
Bases:
objectLocation of radiological findings.
Objects of this type carry bounding-box location of radiological findings on the original images of TBX11k. The radiological findings are defined as such:
0/1: This labels the sign as latent TB (0), or active TB (1)
xmin: horizontal position of bounding box upper-left corner, in pixels
ymin: vertical position of bounding box upper-left corner, in pixels
width: width of the bounding box, in pixels
height: height of the bounding box, in pixels
- property xmax: int#
Return
xcoordinate of rightmost side of bounding box.- Returns:
The rightmost side of the bounding box.
- Return type:
- property ymax: int#
Return
ycoordinate of the lower side of the box.- Returns:
The
ycoordinate of the lower side of the box.- Return type:
- intersection(other)[source]#
Compute the area intersection between bounding boxes.
Notice that screen geometry dictates is slightly different from floating point metrics. Consider a 1D example for the evaluation of the intersection:
2 points : x1 = 1 and x2 = 3, the distance is indeed x2-x1 = 2
2 pixels of index : i1 = 1 and i2 = 3, the segment from pixel i1 to i2 contains 3 pixels ie l = i2 - i1 + 1
- Parameters:
other (
Self) – The other bounding box to check intersections for.- Returns:
The area intersection between this and the other bounding-box in square pixels.
- Return type:
- class mednet.config.data.tbx11k.datamodule.BoundingBoxes(t=[])[source]#
Bases:
Sequence[BoundingBox]A collection of bounding boxes.
- Parameters:
t (
Sequence[BoundingBox]) – A sequence of BoundingBox.
- mednet.config.data.tbx11k.datamodule.DatabaseSample: TypeAlias = tuple[str, int] | tuple[str, int, tuple[tuple[int, int, int, int, int]]]#
Type of objects in our JSON representation for this database.
For healthy/sick (no TB)/latent TB cases, each sample is represented by a filename, relative to the root of the installed database, followed by the number 0 (negative class).
For active TB cases, each sample is represented by a filename, followed by the number 1, and then by 1 or more 5-tuples with radiological finding locations, as described above.
- class mednet.config.data.tbx11k.datamodule.RawDataLoader[source]#
Bases:
RawDataLoaderA specialized raw-data-loader for the TBX11k dataset.
- sample(sample)[source]#
Load a single image sample from the disk.
- Parameters:
sample (
tuple[str,int] |tuple[str,int,tuple[tuple[int,int,int,int,int]]]) – A tuple containing the path suffix, within the dataset root folder, where to find the image to be loaded, an integer, representing the sample label, and possible radiological findings represented by bounding boxes.- Return type:
- Returns:
The sample representation.
- label(sample)[source]#
Load a single image sample label from the disk.
- Parameters:
sample (
tuple[str,int] |tuple[str,int,tuple[tuple[int,int,int,int,int]]]) – A tuple containing the path suffix, within the dataset root folder, where to find the image to be loaded, an integer, representing the sample label, and possible radiological findings represented by bounding boxes.- Returns:
The integer label associated with the sample.
- Return type:
- bounding_boxes(sample)[source]#
Load image annotated bounding-boxes from the disk.
- Parameters:
sample (
tuple[str,int] |tuple[str,int,tuple[tuple[int,int,int,int,int]]]) – A tuple containing the path suffix, within the dataset root folder, where to find the image to be loaded, an integer, representing the sample label, and possible radiological findings represented by bounding boxes.- Returns:
Bounding box annotations, if any available with the sample.
- Return type:
- mednet.config.data.tbx11k.datamodule.make_split(basename)[source]#
Return a database split for the Montgomery database.
- class mednet.config.data.tbx11k.datamodule.DataModule(split_filename)[source]#
Bases:
CachingDataModuleTBX11k dataset for TB detection.
Database reference: [TBX11K-2020]
The original dataset contains samples of healthy, sick (no TB), active and latent TB cases. There is a total of 11702 samples in the database. Healthy and sick individuals are kept in separate folders. Latent and active TB cases are merged in the same directory. One must check the radiological annotations to understand if samples contain either, or both (latent and active TB) signs.
There is one case of patient (file
imgs/tb/tb1199.png), that is inside thetbfolder, but contains no annotations. This sample was excluded from our splits.There are 30 cases of patients that have both active and latent TB radiological signs, over the entire database. Those samples were also excluded from our splits:
imgs/tb/tb0135.png
imgs/tb/tb0142.png
imgs/tb/tb0154.png
imgs/tb/tb0167.png
imgs/tb/tb0190.png
imgs/tb/tb0246.png
imgs/tb/tb0255.png
imgs/tb/tb0279.png
imgs/tb/tb0284.png
imgs/tb/tb0350.png
imgs/tb/tb0378.png
imgs/tb/tb0392.png
imgs/tb/tb0395.png
imgs/tb/tb0501.png
imgs/tb/tb0506.png
imgs/tb/tb0526.png
imgs/tb/tb0543.png
imgs/tb/tb0639.png
imgs/tb/tb0640.png
imgs/tb/tb0667.png
imgs/tb/tb0676.png
imgs/tb/tb0713.png
imgs/tb/tb0786.png
imgs/tb/tb0870.png
imgs/tb/tb0875.png
imgs/tb/tb0945.png
imgs/tb/tb0949.png
imgs/tb/tb0968.png
imgs/tb/tb1104.png
imgs/tb/tb1143.png
Original train dataset samples:
Healthy: 3000
Sick (but no TB): 3000
Active TB only: 473
Latent TB only: 103
Both active and latent TB: 23
Unknown: 1
Total: 6600
Original validation dataset samples:
Healthy: 800
Sick (but no TB): 800
Latent TB only: 36
Active TB only: 157
Both active and latent TB: 7
Total: 1800
Original test dataset samples:
Unknown: 3302
Total: 3302
Because the test set does not have annotations, we generated train, validation and test datasets as such:
The original validation dataset becomes our test set.
The original train dataset is split into new train and validation datasets (validation ratio = 0.203 w.r.t. original train dataset size). The selection of samples is stratified (see comments through our split code, which is shipped alongside this file.)
Data specifications:
Raw data input (on disk): PNG images 8 bits RGB, 512 x 512 pixels
Output image:
Transforms:
Load raw PNG with
PIL
Final specifications:
RGB, encoded as a 3-plane tensor using 32-bit floats, square (512x512 pixels)
Labels: 0 (healthy, latent tb or sick but no tb depending on the protocol), 1 (active tuberculosis)
- Parameters:
split_filename (
str) – Name of the .json file containing the split to load.