MCPcopy Index your code
hub / github.com/DeepLabCut/DeepLabCut / convertcsv2h5

Function convertcsv2h5

deeplabcut/utils/conversioncode.py:26–90  ·  view source on GitHub ↗

Convert (image) annotation files in folder labeled-data from csv to h5. This function allows the user to manually edit the csv (e.g. to correct the scorer name and then convert it into hdf format). WARNING: conversion might corrupt the data. config : string Full path of

(config, userfeedback=True, scorer=None)

Source from the content-addressed store, hash-verified

24
25
26def convertcsv2h5(config, userfeedback=True, scorer=None):
27 """
28 Convert (image) annotation files in folder labeled-data from csv to h5.
29 This function allows the user to manually edit the csv
30 (e.g. to correct the scorer name and then convert it into hdf format).
31 WARNING: conversion might corrupt the data.
32
33 config : string
34 Full path of the config.yaml file as a string.
35
36 userfeedback: bool, optional
37 If true the user will be asked specifically
38 for each folder in labeled-data if the containing csv shall be converted to hdf format.
39
40 scorer: string, optional
41 If a string is given, then the scorer/annotator
42 in all csv and hdf files that are changed, will be overwritten with this name.
43
44 Examples
45 --------
46 Convert csv annotation files for reaching-task project into hdf.
47 >>> deeplabcut.convertcsv2h5('/analysis/project/reaching-task/config.yaml')
48
49 --------
50 Convert csv annotation files for reaching-task project into hdf
51 while changing the scorer/annotator in all annotation files to Albert!
52 >>> deeplabcut.convertcsv2h5('/analysis/project/reaching-task/config.yaml',scorer='Albert')
53 --------
54 """
55 cfg = auxiliaryfunctions.read_config(config)
56 videos = cfg["video_sets"].keys()
57 video_names = [Path(i).stem for i in videos]
58 folders = [Path(config).parent / "labeled-data" / Path(i) for i in video_names]
59 if not scorer:
60 scorer = cfg["scorer"]
61
62 for folder in folders:
63 try:
64 if userfeedback:
65 print("Do you want to convert the csv file in folder:", folder, "?")
66 askuser = input("yes/no")
67 else:
68 askuser = "yes"
69
70 if askuser in ("y", "yes", "Ja", "ha", "oui"): # multilanguage support :)
71 fn = os.path.join(str(folder), "CollectedData_" + cfg["scorer"] + ".csv")
72 # Determine whether the data are single- or multi-animal without loading into memory
73 # simply by checking whether 'individuals' is in the second line of the CSV.
74 with open(fn) as datafile:
75 head = list(islice(datafile, 0, 5))
76 if "individuals" in head[1]:
77 header = list(range(4))
78 else:
79 header = list(range(3))
80 if head[-1].split(",")[0] == "labeled-data":
81 index_col = [0, 1, 2]
82 else:
83 index_col = 0

Callers 1

Calls 4

keysMethod · 0.80
read_configMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected