def predict(img): #predict the class of the input image execute_net(features.get_HoG(img)) #Execute net base don the input image pos = np.argmax(receptors[depth]) #Find the class having max. weight print receptors[depth], dataset.folders[ pos] #Print the folder name corresponding to the class return dataset.folder[pos]
def read_from_folder(path, val): imgs = [] for f in os.listdir(path): ext = os.path.splitext(f)[1] if ext.lower() not in valid_images: continue filename = path+'/'+f img = cv2.imread(filename,0) feat = features.get_HoG(img) imgs.append([feat, val]) return imgs
def read_from_folder(path, val): #Read all the images in the folder imgs = [] for f in os.listdir(path): #list all the files in the folder ext = os.path.splitext(f)[1] #get the file extension if ext.lower() not in valid_images: #check if the extension is valid for the image continue filename = path+'/'+f #create the path of the image img = cv2.imread(filename,0) #read the image if img == None: #Display error if image has nothing print 'Error! Blank Image : ' + filename continue feat = features.get_HoG(img) #Get the features for the image imgs.append([feat, val]) #append features with the categorical output return imgs
def read_from_folder(path, val): #Read all the images in the folder imgs = [] for f in os.listdir(path): #list all the files in the folder ext = os.path.splitext(f)[1] #get the file extension if ext.lower( ) not in valid_images: #check if the extension is valid for the image continue filename = path + '/' + f #create the path of the image img = cv2.imread(filename, 0) #read the image if img == None: #Display error if image has nothing print 'Error! Blank Image : ' + filename continue feat = features.get_HoG(img) #Get the features for the image imgs.append([feat, val]) #append features with the categorical output return imgs
def convert2requiredFormat(data_c): data = [] imgs = data_c.get('data') for i in range(len(imgs)): val = data_c.get('fine_labels')[i] img = data_c.get('data')[i] img = img.reshape((3,32,32)) dst = np.zeros((32,32)) for x in range(32): for y in range(32): dst[x][y] = (img[0][x][y]+img[1][x][y]+img[2][x][y])/3 feat = features.get_HoG(dst) if val == 85: data.append([feat, [0,1]]) else: data.append([feat, [1,0]]) return data
def convert2requiredFormat(data_c): data = [] imgs = data_c.get('data') for i in range(len(imgs)): val = data_c.get('fine_labels')[i] img = data_c.get('data')[i] img = img.reshape((3, 32, 32)) dst = np.zeros((32, 32)) for x in range(32): for y in range(32): dst[x][y] = (img[0][x][y] + img[1][x][y] + img[2][x][y]) / 3 feat = features.get_HoG(dst) if val == 85: data.append([feat, [0, 1]]) else: data.append([feat, [1, 0]]) return data
def execute(inputs): global receptors if inputs.size > 10: start = time.clock() receptors[0] = features.get_HoG(inputs) #compute the feature vector of the input image print 'HoG time : ', (time.clock()-start) start = time.clock() for index in xrange(0,depth): #Execute Neural Network receptors[index+1] = act.activate(synapses[index].dot(receptors[index]) + bias[index+1], False, act_fn[index+1]) print 'NNet time : ', (time.clock()-start) pos = np.argmax(receptors[depth]) #Get the position of the maximum value output if pos == 1: if category[pos] > 0.9: #return 'Tracked' only if more than 90% sure return category[pos] return category[0]
def execute(inputs): global receptors if inputs.size > 10: start = time.clock() receptors[0] = features.get_HoG( inputs) #compute the feature vector of the input image print 'HoG time : ', (time.clock() - start) start = time.clock() for index in xrange(0, depth): #Execute Neural Network receptors[index + 1] = act.activate( synapses[index].dot(receptors[index]) + bias[index + 1], False, act_fn[index + 1]) print 'NNet time : ', (time.clock() - start) pos = np.argmax( receptors[depth]) #Get the position of the maximum value output if pos == 1: if category[ pos] > 0.9: #return 'Tracked' only if more than 90% sure return category[pos] return category[0]
def predict(img): #predict the class of the input image execute_net(features.get_HoG(img)) #Execute net base don the input image pos = np.argmax(receptors[depth]) #Find the class having max. weight print receptors[depth], dataset.folders[pos] #Print the folder name corresponding to the class return dataset.folder[pos]
def predict(img): execute_net(features.get_HoG(img)) print receptors[depth] pos = np.argmax(receptors[depth]) print dataset.folders[pos]