-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathconvertWin2Unix.py
More file actions
73 lines (55 loc) · 2.98 KB
/
convertWin2Unix.py
File metadata and controls
73 lines (55 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script to convert
@author: alex
"""
#!/bin/bash
# make this a callable script.... and add the gpu number to the port!
# python3 runstuff.py 1 (2 or 3)
import subprocess, sys
import numpy as np
import itertools
import os
import pandas as pd
from pathlib import Path
os.environ['DLClight']="True"
import deeplabcut
def convertpaths2unixstyle(projectname,basepath):
config=os.path.join(basepath,projectname,'config.yaml')
#add appending to config path...
config=os.path.join(basepath,config)
cfg=deeplabcut.utils.read_config(config)
cfg['project_path']=os.path.join(basepath,projectname) #config.split('config.yaml')[0]
#videos = cfg['video_sets'].keys()
#video_names = [Path(i).stem for i in videos]
#folders = [Path(config).parent / 'labeled-data' /Path(i) for i in video_names]
folders=[os.path.join(cfg['project_path'],'labeled-data',fn) for fn in os.listdir(os.path.join(cfg['project_path'],'labeled-data')) if "_labeled" not in fn]
print("Creating images with labels by %s." %cfg['scorer'])
print(folders)
for folder in folders:
#try:
print(os.path.join(str(folder),'CollectedData_' + cfg['scorer'] + '.h5'))
DataCombined = pd.read_hdf(os.path.join(str(folder),'CollectedData_' + cfg['scorer'] + '.h5'), 'df_with_missing')
DataCombined.to_csv(os.path.join(str(folder),"CollectedData_" + "original" + ".csv"))
DataCombined.to_hdf(os.path.join(os.path.join(str(folder),'CollectedData_' + "original" + '.h5')),'df_with_missing',format='table', mode='w')
#frame = pd.DataFrame(a, columns = index, index = self.index)
imindex=[]
for fn in DataCombined.index:
imindex.append(os.path.join('labeled-data',folder.split('/')[-1],'img'+fn.split('img')[1]))
for j,bpt in enumerate(cfg['bodyparts']):
index = pd.MultiIndex.from_product([[cfg['scorer']], [bpt], ['x', 'y']],names=['scorer', 'bodyparts', 'coords'])
frame = pd.DataFrame(DataCombined[cfg['scorer']][bpt].values, columns = index, index = imindex)
if j==0:
dataFrame=frame
else:
dataFrame = pd.concat([dataFrame, frame],axis=1)
dataFrame.to_csv(os.path.join(str(folder),"CollectedData_" + cfg['scorer'] + ".csv"))
dataFrame.to_hdf(os.path.join(os.path.join(str(folder),'CollectedData_' + cfg['scorer'] + '.h5')),'df_with_missing',format='table', mode='w')
deeplabcut.utils.write_config(config,cfg)
return cfg,DataCombined
#path where your project sits (in colaboratory), e.g. see
# for our example: https://github.com/AlexEMG/DeepLabCut/blob/master/examples/Colab_TrainNetwork_VideoAnalysis.ipynb
basepath='/content/drive/My Drive/DeepLabCut/examples/'
projectname='Reaching-Mackenzie-2018-08-30'
cfg,DataCombined=convertpaths2unixstyle(projectname,basepath)