Auxiliary function that turns skeleton (list of connected bodypart pairs) into a list of corresponding indices (with regard to the stacked multianimal/uniquebodyparts) Convention: multianimalbodyparts go first!
(cfg, printnames=True)
| 151 | |
| 152 | |
| 153 | def getpafgraph(cfg, printnames=True): |
| 154 | """Auxiliary function that turns skeleton (list of connected bodypart pairs) into a |
| 155 | list of corresponding indices (with regard to the stacked |
| 156 | multianimal/uniquebodyparts) |
| 157 | |
| 158 | Convention: multianimalbodyparts go first! |
| 159 | """ |
| 160 | individuals, uniquebodyparts, multianimalbodyparts = extractindividualsandbodyparts(cfg) |
| 161 | # Attention this order has to be consistent (for training set creation, training, inference etc.) |
| 162 | |
| 163 | bodypartnames = multianimalbodyparts + uniquebodyparts |
| 164 | lookupdict = {bodypartnames[j]: j for j in range(len(bodypartnames))} |
| 165 | |
| 166 | if cfg["skeleton"] is None: |
| 167 | cfg["skeleton"] = [] |
| 168 | |
| 169 | connected = set() |
| 170 | partaffinityfield_graph = [] |
| 171 | for link in cfg["skeleton"]: |
| 172 | if link[0] in bodypartnames and link[1] in bodypartnames: |
| 173 | bp1 = int(lookupdict[link[0]]) |
| 174 | bp2 = int(lookupdict[link[1]]) |
| 175 | connected.add(bp1) |
| 176 | connected.add(bp2) |
| 177 | partaffinityfield_graph.append([bp1, bp2]) |
| 178 | else: |
| 179 | print("Attention, parts do not exist!", link) |
| 180 | |
| 181 | if printnames: |
| 182 | graph2names(cfg, partaffinityfield_graph) |
| 183 | |
| 184 | return partaffinityfield_graph |
| 185 | |
| 186 | |
| 187 | def graph2names(cfg, partaffinityfield_graph): |
nothing calls this directly
no test coverage detected