SVHN
The Street View House Numbers (SVHN) dataset annotates for every photo of a house number all digits appearing on it, including their bounding boxes.
You can see a demo of the dataset here.
Each dataset element is a Python dictionary with the following keys:
"image": a square 3-channel image stored usingtorch.Tensorof typetorch.uint8,"classes": a 1Dtorch.Tensorwith labels of all digits appearing in the image,"bboxes": a[num_digits, 4]2Dtorch.Tensorwith bounding boxes of every digit in the image, each represented as[TOP, LEFT, BOTTOM, RIGHT]coordinates.
The dataset is split into:
train: 10,000 images for training;dev: 1,267 images for development (validation);test: 4,535 images for testing.
npfl138.datasets.svhn.SVHN
Source code in npfl138/datasets/svhn.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
BBox
class-attribute
instance-attribute
Type alias for a bounding box; a list of floats.
TOP
class-attribute
instance-attribute
TOP: int = 0
The index of the top coordinate (y_min) in a bounding box.
LEFT
class-attribute
instance-attribute
LEFT: int = 1
The index of the left coordinate (x_min) in a bounding box.
BOTTOM
class-attribute
instance-attribute
BOTTOM: int = 2
The index of the bottom coordinate (y_max) in a bounding box.
RIGHT
class-attribute
instance-attribute
RIGHT: int = 3
The index of the right coordinate (x_max) in a bounding box.
Element
class-attribute
instance-attribute
The type of a single dataset element.
Dataset
Bases: TFRecordDataset
Source code in npfl138/datasets/svhn.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
__len__
__len__() -> int
Return the number of elements in the dataset.
Source code in npfl138/datasets/svhn.py
59 60 61 | |
__init__
__init__(decode_on_demand: bool = False) -> None
Load the SVHN dataset, downloading it if necessary.
Source code in npfl138/datasets/svhn.py
76 77 78 79 80 | |
evaluate
staticmethod
evaluate(
gold_dataset: Dataset,
predictions: Sequence[tuple[list[int], list[BBox]]],
iou_threshold: float = 0.5,
) -> float
Evaluate the predictions against the gold dataset.
Returns:
-
accuracy(float) –The average accuracy of predicting a complete house number, i.e., all digits and their bounding boxes must be correct.
Source code in npfl138/datasets/svhn.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
evaluate_file
staticmethod
Evaluate the file with predictions against the gold dataset.
Returns:
-
accuracy(float) –The average accuracy of the predicted labels.
Source code in npfl138/datasets/svhn.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
visualize
staticmethod
Visualize the given image plus the recognized objects.
Parameters:
-
image(Tensor) –a torch.Tensor of shape [C, H, W] with dtype torch.uint8
-
labels(list[Any]) –a list of labels to be shown using the
strmethod -
bboxes(list[BBox]) –a list of
BBoxes (fourtuples TOP, LEFT, BOTTOM, RIGHT) -
show(bool) –controls whether to show the figure or return it: if
True, the figure is shown usingplt.show(); ifFalse, theplt.Figureinstance is returned; it can be saved to TensorBoard using the npfl138.Logger.log_figure method of an npfl138.TrainableModule.logger.
Source code in npfl138/datasets/svhn.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |