-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfiles.py
87 lines (64 loc) · 1.94 KB
/
files.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""files.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1lWlQq-4Ghp3LzfC9AsN604CBoFmo6L8V
"""
import numpy as np
import os
import glob
import sys
import scipy.io as sio
train_folders = glob.glob('drive/My Drive/Colab Notebooks/Headposedataset/train/*')
val_folders = glob.glob('drive/My Drive/Colab Notebooks/Headposedataset/val/*')
train_images = []
train_mats=[]
for folder in train_folders:
ffimages = glob.glob(folder + '/*.jpg')
ffmats = glob.glob(folder + '/*.mat')
ffimages.sort()
ffmats.sort()
for f in ffimages:
train_images.append(f)
for fm in ffmats:
train_mats.append(fm)
print(len(train_images))
val_images = []
val_mats=[]
for folder in val_folders:
vimages = glob.glob(folder + '/*.jpg')
vmats = glob.glob(folder + '/*.mat')
vimages.sort()
vmats.sort()
for vf in vimages:
val_images.append(vf)
for vm in vmats:
val_mats.append(vm)
import csv
fields = ['imagepath','matpath']
train_rows = []
for folderi,folderm in zip(train_images,train_mats):
trow = str(folderi),str(folderm)
train_rows.append(trow)
val_rows = []
for folderi,folderm in zip(val_images,val_mats):
vrow = str(folderi),str(folderm)
val_rows.append(trow)
with open("drive/My Drive/Colab Notebooks/train.csv", 'w') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)
# writing the fields
csvwriter.writerow(fields)
# writing the data rows
csvwriter.writerows(train_rows)
val_rows = []
for folderi,folderm in zip(val_images,val_mats):
vrow = str(folderi),str(folderm)
val_rows.append(vrow)
with open("drive/My Drive/Colab Notebooks/val.csv", 'w') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)
# writing the fields
csvwriter.writerow(fields)
# writing the data rows
csvwriter.writerows(val_rows)