コード例 #1
0
ファイル: GenFile.py プロジェクト: TimePi/Python
 def gen_line(line,province,touch_time,spliter = u'/**********/'):
     words = line.split('|')
     if len(words) != 9:
         return None
     result = (u'%s'+spliter)*21+u'\n'
     compname = words[0]
     compkeyname = words[0]
     province = province
     TPYE = Classify.predict(words[3])
     postdate = words[4]
     level = Classify.get_risk_score(words[3])
     channel = u'全国企业信用公示系统('+province+u')'
     rank = ''
     TPYE_2 = ''
     postdate_2 = ''
     level_2=''
     channel_2=''
     rank_2=''
     updatetime = unicode(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(touch_time)))
     
     subcomp	= words[0]
     createtime	= updatetime
     
     privince_field = ''
     city_field = ''
     id = ''
     reg_no = words[1]
     comp_no = ''
     result = result % (compname,compkeyname,province,TPYE,postdate,level,channel,rank,TPYE_2,postdate_2,level_2,channel_2,rank_2,updatetime,subcomp,createtime,privince_field,city_field,id,reg_no,comp_no)
     result = result.encode('gbk','ignore')  
     return result
コード例 #2
0
    def gen_line(line, province, touch_time, spliter=u'/**********/'):
        words = line.split('|')
        if len(words) != 9:
            return None
        result = (u'%s' + spliter) * 21 + u'\n'
        compname = words[0]
        compkeyname = words[0]
        province = province
        TPYE = Classify.predict(words[3])
        postdate = words[4]
        level = Classify.get_risk_score(words[3])
        channel = u'全国企业信用公示系统(' + province + u')'
        rank = ''
        TPYE_2 = ''
        postdate_2 = ''
        level_2 = ''
        channel_2 = ''
        rank_2 = ''
        updatetime = unicode(
            time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(touch_time)))

        subcomp = words[0]
        createtime = updatetime

        privince_field = ''
        city_field = ''
        id = ''
        reg_no = words[1]
        comp_no = ''
        result = result % (compname, compkeyname, province, TPYE, postdate,
                           level, channel, rank, TPYE_2, postdate_2, level_2,
                           channel_2, rank_2, updatetime, subcomp, createtime,
                           privince_field, city_field, id, reg_no, comp_no)
        result = result.encode('gbk', 'ignore')
        return result
コード例 #3
0
def Extract_lisenceplate(model, license_plate_path):
    for num, image_inp in enumerate(
            glob.glob(conf['Indian_cars']) + glob.glob(conf['Foreign_cars'])):
        print(image_inp)
        image_to_classify = cv2.imread(image_inp)
        # cv2.imshow('image',image_to_classify)
        # cv2.waitKey(0)
        # cv2.destroyAllWindows()
        image_resized = Tools.resize(image_to_classify, height=500)
        pred_dict = Classify().classify_new_instance(image_resized, model)
        # print (pred_dict)

        # print (model)
        probs = []
        for image_fname, prob in pred_dict.items():  #range(0,len(pred_dict)):
            probs.append(prob[1])
            # print (image_fname)
        probs = np.array(probs)
        ind = np.where(probs == np.max(probs))[0]

        print(ind)

        for filename in np.array(list(pred_dict.keys()))[ind]:
            copyfile(
                conf['Regions_of_Intrest'] + filename, license_plate_path +
                filename.split(".")[0] + "_" + str(num) + ".jpg")
コード例 #4
0
ファイル: CheckFaceService.py プロジェクト: feveral/wisedoor
 def __init__(self):
     self._camera = Camera(0)
     self._model = Model(config.USER_EMAIL, config.USER_PASSWORD,
                         config.EQUIPMENT_NAME)
     self._classify = Classify(self._model)
     self._align = OpencvAlign()
     self._timer = Timer()
     self._fail_count = 0
     self._success = True
     self._success_task = None
     self._record_task = None
     self.start = time.time()
コード例 #5
0
ファイル: Main.py プロジェクト: eric07/ML-app
class Main():
    url = None
    tweets = None
    fetch = None
    parse = None
    classifier = Classify("trainSet.json", "dictionary.json",
                          "./liveTrain.json", "./pastTrain.json",
                          "./liveTrainDic.json", "./pastTrainDic.json")
    fetch = Fetch()
    print(classifier.classifyOne(fetch.tweets[0], 1, 1))

    # Load parsed tweets
    def loadTweets(self):
        json_data = open("parsedTweets.json")
        data = json.load(json_data)
        return data

    # Function to check tweet exists
    def getTweet(self, tweet_id):
        for line in self.tweets:
            if int(line['id']) == tweet_id:
                return line

    # Save a tweet in json file
    def save(self):
        with open('./parsedTweets.json', 'w+') as outfile:
            outfile.write(json.dumps(self.tweets, indent=4))
コード例 #6
0
def Extract_lisenceplates(model, extracted_license_plate_path):
	for num, image_inp in enumerate(glob.glob(conf['Images_to_classify']) ):
		print (image_inp)
		image_to_classify = cv2.imread(image_inp)
		# cv2.imshow('image',image_to_classify)
		# cv2.waitKey(0)
		# cv2.destroyAllWindows()
		image_resized = Tools.resize(image_to_classify, height=500)
		pred_dict = Classify().classify_new_instance(image_resized,model)
		# print (pred_dict)

		# print (model)
		probs = []
		coords=[]
		for image_fname,s_and_c in pred_dict.items():#range(0,len(pred_dict)):
			prob=s_and_c[1]
			x=s_and_c[2]
			y=s_and_c[3]
			w=s_and_c[4]
			h=s_and_c[5]
			probs.append(prob)
			coords.append([x,y,w,h])
		        # print (image_fname)
		probs = np.array(probs)
		coords = np.array(coords)
		ind = np.where(probs == np.max(probs))[0]


		filenames=pred_dict.keys()
		for i in ind:
			filename=filenames[i]
			copyfile(conf['Regions_of_Intrest']+filename, extracted_license_plate_path+filename.split(".")[0]+"_"+str(num)+".jpg")
			coord=coords[i]
			x=coord[0]
			y=coord[1]
			w=coord[2]
			h=coord[3]
			cv2.rectangle(image_resized,(x,y),(x+w,y+h),(0,255,0),2)


		cv2.namedWindow("Show")
		cv2.moveWindow("Show", 10, 50)
		cv2.imshow("Show",image_resized)
		cv2.waitKey()
		cv2.destroyAllWindows()
コード例 #7
0
ファイル: main.py プロジェクト: t409wu/stuff
def main():

    problem = Training()

    accuracy_training_for_each_sample_size = []
    accuracy_testing_for_each_sample_size = []

    for i in range(0, 10):
        num_examples = i * 1

        training_set = ParseTools.get_training_set(None, num_examples + 2)
        testing_set = ParseTools.get_testing_set(None)

        problem.create_decision_tree(training_set)

        accuracy_training_set = Classify.get_accuracy(problem.decision_tree,
                                                      training_set)
        accuracy_testing_set = Classify.get_accuracy(problem.decision_tree,
                                                     testing_set)

        accuracy_training_for_each_sample_size.append(accuracy_training_set)
        accuracy_testing_for_each_sample_size.append(accuracy_testing_set)

    training_set_accuracy_file = open("./results/training_set_accuracy.txt",
                                      "w")
    print "training set accuracy"
    for j in range(0, len(accuracy_training_for_each_sample_size)):
        print "num examples: " + str(j) + " acc: " + str(
            accuracy_training_for_each_sample_size[j])
        training_set_accuracy_file.write(
            str(accuracy_training_for_each_sample_size[j]) + '\n')
    training_set_accuracy_file.close()

    print "\n\n"

    testing_set_accuracy_file = open("./results/testing_set_accuracy.txt", "w")
    print "testing set accuracy"
    for j in range(0, len(accuracy_testing_for_each_sample_size)):
        print "num examples: " + str(j) + " acc: " + str(
            accuracy_testing_for_each_sample_size[j])
        testing_set_accuracy_file.write(
            str(accuracy_testing_for_each_sample_size[j]) + '\n')
    testing_set_accuracy_file.close()
コード例 #8
0
def Extract_lisenceplate():
    for image_inp in glob.glob(conf['Indian_cars']):
        print(image_inp)
        image_to_classify = cv2.imread(image_inp)
        # cv2.imshow('image',image_to_classify)
        # cv2.waitKey(0)
        # cv2.destroyAllWindows()
        image_resized = Tools.resize(image_to_classify, height=500)
        pred_dict = Classify().classify_new_instance(image_resized, model)
        print(pred)
        break
コード例 #9
0
def test_models():
    conf = Configuration.get_datamodel_storage_path()
    for files in glob.glob(
            conf['All_Models']):  # Test Using all the models saved in the disk
        classifier = open(files).read()
        classifier = cPickle.loads(classifier)

        image_to_classify = cv2.imread(image_to_classify_path)
        image_resized = imutils.resize(image_to_classify, height=500)
        pred = Classify().classify_new_instance(image_resized, classifier)

        print classifier
        for i in range(0, len(pred)):
            if pred[i][0] == 1:
                print pred[i]
コード例 #10
0
 def classify(self):
     """the function starts the classify process by inboking it's init method"""
     Classify(os.path.join(self.__path, 'test.csv'), self.__rang,
              self.__numeric, self.__statistics, self.__k, self.__classes,
              self.__abs_n, self)
     self.view.Build_Button.configure(state="active")
コード例 #11
0
output_one_hot = to_one_hot(output)

# Huperparameters for tuning
hidden_neuron_list = [6]
epochs = 100
runs = 30
lr_rate = 0.001
lmbd = 0

AUC = []
accuracy = []

# Defining the parameters run for grid search
acc_test = np.zeros((runs, epochs))
acc_train = np.zeros((runs, epochs))
clf = Classify(hidden_activation="leaky_ReLU", output_activation="softmax")

for i in tqdm(range(runs)):
    X_train, X_test, Y_train, Y_test = train_test_split(input_data,
                                                        output_one_hot,
                                                        test_size=0.2)
    Scaler = preprocessing.StandardScaler()
    X_train_scaled = Scaler.fit_transform(X_train)
    X_test_scaled = Scaler.transform(X_test)
    nn = NeuralNetwork(X_train_scaled,
                       Y_train,
                       problem=clf,
                       n_hidden_neurons_list=hidden_neuron_list,
                       n_output_neurons=2,
                       epochs=epochs,
                       batch_size=100,
コード例 #12
0
from Classify import Classify
import time

if __name__ == "__main__":
    start = time.clock()
    classify = Classify()
    trainingPath = "C:\\Users\\ace\\Desktop\\newData\\training"
    testPath = "C:\\Users\\ace\\Desktop\\newData\\testing"

    featureExtraType = "surf"
    result = classify.algoSVM(trainingPath, testPath, featureExtraType)

    end = time.clock()
    print "run time: %f s" % (end - start)

    print result
    print "Taux global:%f" % (result.trace() / result.sum())
コード例 #13
0
ファイル: CheckFaceService.py プロジェクト: feveral/wisedoor
class CheckFaceService():
    def __init__(self):
        self._camera = Camera(0)
        self._model = Model(config.USER_EMAIL, config.USER_PASSWORD,
                            config.EQUIPMENT_NAME)
        self._classify = Classify(self._model)
        self._align = OpencvAlign()
        self._timer = Timer()
        self._fail_count = 0
        self._success = True
        self._success_task = None
        self._record_task = None
        self.start = time.time()

    def start_check(self):
        if self._model.is_empty:
            return
        self._timer.start_timing()
        self._fail_count = 0
        self._success = False
        while self._fail_count < 3 and not self._success:
            frame = self._camera.CatchImage()
            start = time.time()
            if (is_blurr(frame)):
                continue
            #if (self._timer.get_time_count() >= 5):
            #    return
            if (self._align.cut(frame)):
                classify_result = self._classify.classify_image(
                    self._align.image)
                self._classify_result_handler(classify_result, frame)
                self._timer.start_timing()
                self._align.clear()
            print(time.time() - start)

    @property
    def model(self):
        return self._model

    @property
    def camera(self):
        return self._camera

    @property
    def check_success_task(self):
        return self._success_task

    @property
    def record_task(self):
        return self._record_task

    @check_success_task.setter
    def check_success_task(self, task):
        self._success_task = task

    @record_task.setter
    def record_task(self, task):
        self._record_task = task

    def _classify_result_handler(self, classify_result, frame):
        if (classify_result[0] == 'unknown'):
            print(str(classify_result[0]) + ":" + str(classify_result[1]))
            print('open lock fail')
            self._fail_count += 1
            if (self._fail_count >= 3 and self.record_task != None):
                self.record_task("fail", "face", classify_result[0], frame)

        else:
            self.start = time.time()
            print(str(classify_result[0]) + ":" + str(classify_result[1]))
            print('open lock')
            bulbController.setGreenBulbOpen()
            bulbController.setYellowBulbOpen()
            if (self.record_task != None):
                self.record_task("success", "face", classify_result[0], frame)
            self._success = True
            self._success_task()