Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions evaluate_acc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Evalute the accuracy

import numpy as np
from load_datas import *
import pdb


# ground truth label path
GT_label_path = '../../labels/'

# prediction label path
pred_label_path = '../../labels/'

#load_train_labels(label_path,'obj',setting_index=0)
GT =load_test_labels(GT_label_path, 'obj',setting_index=0)
pred=load_test_labels(pred_label_path, 'obj',setting_index=0)


GT_seq=np.zeros((0))
pred_seq=np.zeros((0))

for i in xrange(len(GT)):
GT_seq=np.append(GT_seq, GT[i])
pred_seq =np.append(pred_seq, pred[i])

correct = np.count_nonzero(GT_seq==pred_seq)
total = len(GT_seq)
print "testing acc. = %.2f%%, %d/%d" %(correct/float(total)*100, correct, total)
102 changes: 102 additions & 0 deletions load_datas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#############################################################################################################
# load features and labels #
# feature dimension : (N,d), (i.e., N*4096), label dimension : (N,) #
# type of all the output will be "list" #
#############################################################################################################
# There are two different setting of training and testing : #
# The default setting (setting-0) is splitting the dataset into two parts, half for training, half for #
# testing. Training index: lab-1234, office-123, house-123. Testing index: lab-5678, office-456, house-456 #
#############################################################################################################

import sys, os
import numpy as np
import pdb
import warnings

def load_one_label_seq(path):
npy = np.load(path)
#print path
return npy


def load_label_seqs(path, mode, index):
labels=[]
for i in range(len(index)):
loc = index[i][0]
idx = index[i][1]
labelnpy = os.path.join(path,loc,mode+"_left"+str(idx)+'.npy')
labels.append(load_one_label_seq(labelnpy))
labelnpy = os.path.join(path,loc,mode+"_right"+str(idx)+'.npy')
labels.append(load_one_label_seq(labelnpy))
return labels

def gen_index(setting_index):
train_index=[]
test_index =[]
if setting_index == 0:
for i in range(1,9):
if i <= 4:
train_index.append(('lab',i))
else:
test_index.append(('lab',i))
for i in range(1,7):
if i <= 3:
train_index.append(('office',i))
else:
test_index.append(('office',i))
for i in range(1,7):
if i <= 3:
train_index.append(('house',i))
else:
test_index.append(('house',i))
elif setting_index == 1:
for i in range(1,9):
train_index.append(('lab',i))
for i in range(1,7):
train_index.append(('office',i))
for i in range(1,7):
test_index.append(('house',i))
else:
raise ValueError ('error setting index')

return train_index, test_index



def gen_index_process(index=None, setting_index=None):
if index == None:
if setting_index==None:
raise ValueError('Setting index can not be none')
else:
train_index, test_index = gen_index(setting_index)
return train_index, test_index


def load_train_labels(path, mode, index=None, setting_index=None):
if index == None:
index,_ = gen_index_process(index,setting_index)
else:
if setting_index != None:
warnings.warn('setting_index has no effect when given particular index')
labels = load_label_seqs(path, mode, index)
return labels

def load_test_labels(path, mode, index=None, setting_index=None):
if index == None:
_,index = gen_index_process(index,setting_index)
else:
if setting_index != None:
warnings.warn('setting_index has no effect when given particular index')
labels = load_label_seqs(path, mode, index)
return labels


def load_all_labels(path, mode, setting_index):
train_index, test_index = gen_index(setting_index)
train_labels = load_train_labels(path, mode,train_index)
test_labels = load_train_labels(path, mode,test_index)
return train_labels, test_labels




42 changes: 7 additions & 35 deletions results/index.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
# Your Name <span style="color:red">(id)</span>
# Caroline <span style="color:red">(106062515)</span>

#Project 5: Deep Classification

## Overview
The project is related to
> quote

The project is VGG model training on given images and labels.

## Implementation
1. One
* item
* item
2. Two

```
Code highlights
```
1. test_load_datas.py, load_datas.py: loads labels and training images
2. ty.py: VGG model

## Installation
* Other required packages.
* How to compile from source?
* pre-trained VGG: https://drive.google.com/open?id=0B1d4hs5v8ZQocDNXS1Njb2tQOVk
* run python tf.py

### Results

<table border=1>
<tr>
<td>
<img src="placeholder.jpg" width="24%"/>
<img src="placeholder.jpg" width="24%"/>
<img src="placeholder.jpg" width="24%"/>
<img src="placeholder.jpg" width="24%"/>
</td>
</tr>

<tr>
<td>
<img src="placeholder.jpg" width="24%"/>
<img src="placeholder.jpg" width="24%"/>
<img src="placeholder.jpg" width="24%"/>
<img src="placeholder.jpg" width="24%"/>
</td>
</tr>

</table>
After training 2 epochs, average accuracy: 0.3~0.4


139 changes: 139 additions & 0 deletions test_load_datas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import numpy as np
from load_datas import *
import pdb
import re
path_data = os.environ.get("GRAPE_DATASET_DIR")

#label_path='/home/yoooosing/CEDL/hw1/labels/'
label_path = os.path.join(path_data,'labels')


# load all labels
train_labels0, test_labels0 = load_all_labels(label_path, 'obj',0)
#print len(train_labels0)
#print len(test_labels0)
# load train/test labels automatically
#train_labels = load_train_labels(label_path,'obj',setting_index=1)
#test_labels = load_test_labels(label_path,'obj',setting_index=1)

# load particular index
# You can load only part of the directories, the index of directories should be a list.
# Such like [(location1, id), (location2, id) ...], ex. [('lab',1), ('lab',2), ('office',1)]
# No setting_index required now.
# train_labels = load_train_labels(label_path,'FA',index=[['lab',1],['lab',2],['office',3]])
# test_labels = load_test_labels(label_path,'FA',index=[['lab',1],['lab',2],['office',3]])



# load train/test images

train_images = []
duplicate_train_labels = []
#image_path1='/home/yoooosing/CEDL/hw1/train/lab'
#image_path2='/home/yoooosing/CEDL/hw1/train/office'
#image_path3='/home/yoooosing/CEDL/hw1/train/house'

image_path1 = os.path.join(path_data, 'frames/train/lab')
image_path2 = os.path.join(path_data, 'frames/train/office')
image_path3 = os.path.join(path_data, 'frames/train/house')



for i in xrange(1,5):
temp_path_l = os.listdir(os.path.join(image_path1,str(i),'Lhand'))
temp_path_l = sorted(temp_path_l, key=lambda x: int(re.sub('\D', '', x)))
temp_path_l = [os.path.join(image_path1,str(i),'Lhand',t) for t in temp_path_l]
train_images.extend(temp_path_l)
temp_path_r = os.listdir(os.path.join(image_path1,str(i),'Rhand'))
temp_path_r = sorted(temp_path_r, key=lambda x: int(re.sub('\D', '', x)))
temp_path_r = [os.path.join(image_path1,str(i),'Rhand',t) for t in temp_path_r]
train_images.extend(temp_path_r)

for i in xrange(1,4):
temp_path_l = os.listdir(os.path.join(image_path2,str(i),'Lhand'))
temp_path_l = sorted(temp_path_l, key=lambda x: int(re.sub('\D', '', x)))
temp_path_l = [os.path.join(image_path2,str(i),'Lhand',t) for t in temp_path_l]
train_images.extend(temp_path_l)
temp_path_r = os.listdir(os.path.join(image_path2,str(i),'Rhand'))
temp_path_r = sorted(temp_path_r, key=lambda x: int(re.sub('\D', '', x)))
temp_path_r = [os.path.join(image_path2,str(i),'Rhand',t) for t in temp_path_r]
train_images.extend(temp_path_r)

for i in xrange(1,4):
temp_path_l = os.listdir(os.path.join(image_path3,str(i),'Lhand'))
temp_path_l = sorted(temp_path_l, key=lambda x: int(re.sub('\D', '', x)))
temp_path_l = [os.path.join(image_path3,str(i),'Lhand',t) for t in temp_path_l]
train_images.extend(temp_path_l)
temp_path_r = os.listdir(os.path.join(image_path3,str(i),'Rhand'))
temp_path_r = sorted(temp_path_r, key=lambda x: int(re.sub('\D', '', x)))
temp_path_r = [os.path.join(image_path3,str(i),'Rhand',t) for t in temp_path_r]
train_images.extend(temp_path_r)

for i in xrange(0,8):
duplicate_train_labels.extend(train_labels0[i])
for i in xrange(8,14):
duplicate_train_labels.extend(train_labels0[i])
for i in xrange(14,20):
duplicate_train_labels.extend(train_labels0[i])

test_images = []
duplicate_test_labels = []
#image_path1='/home/yoooosing/CEDL/hw1/test/lab'
#image_path2='/home/yoooosing/CEDL/hw1/test/office'
#image_path3='/home/yoooosing/CEDL/hw1/test/house'

image_path1 = os.path.join(path_data, 'frames/test/lab')
image_path2 = os.path.join(path_data, 'frames/test/office')
image_path3 = os.path.join(path_data, 'frames/test/house')

for i in xrange(1,5):
temp_path_l = os.listdir(os.path.join(image_path1,str(i),'Lhand'))
temp_path_l = sorted(temp_path_l, key=lambda x: int(re.sub('\D', '', x)))
temp_path_l = [os.path.join(image_path1,str(i),'Lhand',t) for t in temp_path_l]
test_images.extend(temp_path_l)
temp_path_r = os.listdir(os.path.join(image_path1,str(i),'Rhand'))
temp_path_r = sorted(temp_path_r, key=lambda x: int(re.sub('\D', '', x)))
temp_path_r = [os.path.join(image_path1,str(i),'Rhand',t) for t in temp_path_r]
test_images.extend(temp_path_r)

for i in xrange(1,4):
temp_path_l = os.listdir(os.path.join(image_path2,str(i),'Lhand'))
temp_path_l = sorted(temp_path_l, key=lambda x: int(re.sub('\D', '', x)))
temp_path_l = [os.path.join(image_path2,str(i),'Lhand',t) for t in temp_path_l]
test_images.extend(temp_path_l)
temp_path_r = os.listdir(os.path.join(image_path2,str(i),'Rhand'))
temp_path_r = sorted(temp_path_r, key=lambda x: int(re.sub('\D', '', x)))
temp_path_r = [os.path.join(image_path2,str(i),'Rhand',t) for t in temp_path_r]
test_images.extend(temp_path_r)

for i in xrange(1,4):
temp_path_l = os.listdir(os.path.join(image_path3,str(i),'Lhand'))
temp_path_l = sorted(temp_path_l, key=lambda x: int(re.sub('\D', '', x)))
temp_path_l = [os.path.join(image_path3,str(i),'Lhand',t) for t in temp_path_l]
test_images.extend(temp_path_l)
temp_path_r = os.listdir(os.path.join(image_path3,str(i),'Rhand'))
temp_path_r = sorted(temp_path_r, key=lambda x: int(re.sub('\D', '', x)))
temp_path_r = [os.path.join(image_path3,str(i),'Rhand',t) for t in temp_path_r]
test_images.extend(temp_path_r)

for i in xrange(0,8):
duplicate_test_labels.extend(test_labels0[i])
for i in xrange(8,14):
duplicate_test_labels.extend(test_labels0[i])
for i in xrange(14,20):
duplicate_test_labels.extend(test_labels0[i])

#print '\n'.join(train_images)
#print len(train_images)
#print len(duplicate_train_labels)
#print len(test_images)
#print len(duplicate_test_labels)


#for i in xrange(len(train_labels)):
# if np.count_nonzero(train_labels0[i] == train_labels[i]) != len(train_labels0[i]):
# print 'error'

#for i in xrange(len(test_labels)):
# if np.count_nonzero(test_labels0[i] == test_labels[i]) != len(test_labels[i]):
# print 'error'
Loading