MCPcopy Create free account
hub / github.com/DeepLabCut/DeepLabCut / generate_model_output_plots

Function generate_model_output_plots

deeplabcut/core/visualization.py:143–234  ·  view source on GitHub ↗

Generates model output plots (maps) for an image and saves them to disk. Args: output_folder: The folder in which the plots should be saved. image_name: The name of the image for which the plots were generated. bodypart_names: The names of bodyparts the model outputs.

(
    output_folder: Path,
    image_name: str,
    bodypart_names: list[str],
    bodyparts_to_plot: list[str],
    image: np.ndarray,
    scmap: np.ndarray,
    locref: np.ndarray | None = None,
    paf: np.ndarray | None = None,
    paf_graph: list[tuple[int, int]] | None = None,
    paf_all_in_one: bool = True,
    paf_colormap: str = "rainbow",
    output_suffix: str = "",
)

Source from the content-addressed store, hash-verified

141
142
143def generate_model_output_plots(
144 output_folder: Path,
145 image_name: str,
146 bodypart_names: list[str],
147 bodyparts_to_plot: list[str],
148 image: np.ndarray,
149 scmap: np.ndarray,
150 locref: np.ndarray | None = None,
151 paf: np.ndarray | None = None,
152 paf_graph: list[tuple[int, int]] | None = None,
153 paf_all_in_one: bool = True,
154 paf_colormap: str = "rainbow",
155 output_suffix: str = "",
156) -> None:
157 """Generates model output plots (maps) for an image and saves them to disk.
158
159 Args:
160 output_folder: The folder in which the plots should be saved.
161 image_name: The name of the image for which the plots were generated.
162 bodypart_names: The names of bodyparts the model outputs.
163 bodyparts_to_plot: The names of bodyparts that should be plot.
164 image: Shape (height, width, channels). The image on which the model was run.
165 scmap: Shape (height, width, num_bodyparts). The scoremaps output by the model.
166 locref: Shape (height, width, num_bodyparts, 2). Optionally, the location
167 refinement fields output by the model.
168 paf: Shape (height, width, 2 * len(paf_graph)). Optionally, the part-affinity
169 fields output by the model.
170 paf_graph: Must be set if paf is not None. The PAF graph used to assemble.
171 paf_all_in_one: Whether to plot all PAFs in a single image.
172 paf_colormap: The colormap to use for the PAF maps.
173 output_suffix: The filename suffix for the maps to output.
174 """
175
176 def _filename(map_name) -> str:
177 return f"{image_name}_{map_name}_{output_suffix}.png"
178
179 to_plot = [i for i, bpt in enumerate(bodypart_names) if bpt in bodyparts_to_plot]
180 if len(to_plot) > 1:
181 map_ = scmap[:, :, to_plot].sum(axis=2)
182 elif len(to_plot) == 1 and len(bodypart_names) > 1:
183 map_ = scmap[:, :, to_plot[0]]
184 else:
185 map_ = scmap[..., 0]
186
187 fig1, _ = visualize_scoremaps(image, map_)
188 fig1.savefig(output_folder / _filename("scmap"))
189
190 if locref is not None:
191 if len(to_plot) > 1:
192 map_ = scmap[:, :, to_plot]
193 locref_x_ = locref[:, :, to_plot, 0]
194 locref_y_ = locref[:, :, to_plot, 1]
195 # only get the locref fields around their respective detections
196 locref_x_[map_ < 0.5] = 0
197 locref_y_[map_ < 0.5] = 0
198 # combine locrefs
199 map_ = map_.sum(axis=2)
200 locref_x_ = locref_x_.sum(axis=2)

Callers

nothing calls this directly

Calls 5

_filenameFunction · 0.85
visualize_scoremapsFunction · 0.70
visualize_locrefsFunction · 0.70
visualize_pafFunction · 0.70
closeMethod · 0.45

Tested by

no test coverage detected