class CorePy(object): def __init__(self, path, predictorType): super(CorePy, self).__init__() self.image = ImageFactory() self.path = path if predictorType == "kppv": self.predictor = Kppv() # elif predictorType == "mlp": # self.predictor = Mlp() else: self.predictor = None self.max_distance = 0 def setImage(self, path_to_image): self.image.initialize(path_to_image) def predict_current(self): predicted_classes, result = np.zeros( (len(self.image.feature_list), 2)), 0 for x in range(0, len(self.image.feature_list)): predicted_classes[x], distance = self.predictor.predict( self.image.feature_list[x]) result += predicted_classes[x] if distance >= 0: self.max_distance = max(self.max_distance, distance) self.image.class_list = predicted_classes pass def train_predictor(self): self.predictor.train(self.image.feature_list, self.image.class_list)
class CorePy(object): def __init__(self, path, predictorType): super(CorePy, self).__init__() self.image = ImageFactory() self.path = path if predictorType == "kppv": self.predictor = Kppv() # elif predictorType == "mlp": # self.predictor = Mlp() else: self.predictor = None self.max_distance = 0 def setImage(self, path_to_image): self.image.initialize(path_to_image) def predict_current(self): predicted_classes, result = np.zeros((len(self.image.feature_list), 2)), 0 for x in range(0,len(self.image.feature_list)): predicted_classes[x], distance = self.predictor.predict(self.image.feature_list[x]) result += predicted_classes[x] if distance >= 0: self.max_distance = max(self.max_distance, distance) self.image.class_list = predicted_classes pass def train_predictor(self): self.predictor.train(self.image.feature_list, self.image.class_list)
def getContentBoxesWorker(socketID, filename): # instantiate a publisher (send to nodejs server) context = zmq.Context() socket = context.socket(zmq.PUB) socket.bind("tcp://127.0.0.1:5556") # msg["socketID"] is clientID, msg["filename"] is path Im = ImageFactory() path = "../public/" + filename Im.initialize(path) # initialize class_list Im.class_list = np.zeros((len(Im.feature_list), 2)) for x in range(0, len(Im.feature_list)): Im.class_list[x][0] = 1.0 # create JSON string before ... json_string = '{"socketID":"' + socketID + '", "contentBoxes" :' + tojson([Im.content_list, Im.class_list]) + "}" socket.send_string(json_string) pass
def getContentBoxesWorker(socketID, filename): # instantiate a publisher (send to nodejs server) context = zmq.Context() socket = context.socket(zmq.PUB) socket.bind("tcp://127.0.0.1:5556") # msg["socketID"] is clientID, msg["filename"] is path Im = ImageFactory() path = "../public/" + filename Im.initialize(path) # initialize class_list Im.class_list = np.zeros((len(Im.feature_list), 2)) for x in range(0, len(Im.feature_list)): Im.class_list[x][0] = 1.0 # create JSON string before ... json_string = '{"socketID":"' + socketID + '", "contentBoxes" :' + tojson( [Im.content_list, Im.class_list]) + '}' socket.send_string(json_string) pass