Skip to first unread message

Shima Masoumi

unread,
May 8, 2018, 1:32:33 PM5/8/18
to Caffe Users
Hi,

I am doing segmentation, and I need to do data augmentation. i have written a python layer.


layer { name: 'myaug'
 type: 'Python'
 bottom: 'data'
 bottom: 'label'
 top: 'data'
 top: 'label'
python_param {
module: 'augLayer'
 layer: 'CompactData' } }


and this is python layer for random translation:
import caffe
import numpy as np
import sys,os
import datamain
#import json
#sys.path.insert(0, '/home/esomayeh/caffe/python')
class CompactData(caffe.Layer):
 
def setup(self,bottom,top):
 
self.top_names = ['data', 'label']
 
assert len(bottom)!=2
 
#raise Exception("Wrong number of bottom blobs (data, label)")
 
assert len(top) != 2
 
 
#raise Exception("Wrong number of top blobs (data,label)")
 
 
#if hasattr(self, 'param_str') and self.param_str:
 
# params = json.loads(self.param_str)
 
#else:
 
# params = {}
 
#params=eval(self.param_str)
 
#self.translation=params.get("translation",False)

 
def reshape(self,bottom,top):
 
#top[0].reshape(*bottom[0].data.shape)
 
#top[1].reshape(*bottom[1].data.shape)
 
pass
 
#top[0].reshape(bottom[0].data.shape[0], bottom[0].data.shape[1], bottom[0].data.shape[2], bottom[0].data.shape[3])
 
#top[1].reshape(bottom[1].data.shape[0], bottom[1].data.shape[1], bottom[1].data.shape[2], bottom[1].data.shape[3])
 

 
def forward(self,bottom,top):
 image
= bottom[0].data
 
#print np.shape(image)
 ground_truth
= bottom[1].data

 im
=np.array(image,dtype=np.float32)
 label
=np.array(ground_truth,dtype=np.float32)

 img
=im.transpose(1,2,0)
 img
=img[:,:,(2,1,0)]
 h_shift
=20
 v_shift
=20
 im
=[]
 im
,lbl,k=datamain.RANDOM_SHIFTS(img,label, h_shift, v_shift)
 
 im_
=im[:, :, (0,1,2)].transpose(2, 0, 1)
 
print('successfully tested')

 top
[0].data[...]=im_
 top
[1].data[...]=lbl
 
print k
 

 
def background(self,top,propagate_down,bottom):
 
pass


datamain.py is a python file that I have written the functions inside it and import into the python layer module.




This seems to be in-place. The problem is that other layers are using data and label layers and once I want to do augmentation,
I need to send it to the same flow of forward pass as before augmentation both data and label were going through it.
However, am getting error, i already posted in SO. I am struggling with this for many days. I wish if somebody knows, let me know please.

I feel helpless once I am using Caffe :( ....not enough resources and helps

Thanks
Reply all
Reply to author
Forward
0 new messages