def evaluate_embeddings(embeddings): X, Y = read_node_label('../data/wiki/wiki_labels.txt') tr_frac = 0.8 print("Training classifier using {:.2f}% nodes...".format( tr_frac * 100)) clf = Classifier(embeddings=embeddings, clf=LogisticRegression()) clf.split_train_evaluate(X, Y, tr_frac)
def test_1NN(digitsdat, selected, all_test_m): for testm in all_test_m: classifier = Classifier() classifier.build_model(digitsdat.X[selected[0:testm], :], digitsdat.y[ selected[0:testm]]) print("m=%d error=%f" % ( testm, classifier.classify(digitsdat.testX, digitsdat.testy)))
def classify(vectors, args): if not os.path.isfile(args.classifydir + '_labels.txt'): return defaultdict(lambda: 0) X, Y = read_node_label(args.classifydir + '_labels.txt') # print("Training classifier using {:.2f}% nodes...".format(args.train_percent * 100)) clf = Classifier(vectors=vectors, clf=LogisticRegression(solver="lbfgs", max_iter=4000)) # scores = clf.split_train_evaluate(X, Y, args.train_percent) features, labels, graph, idx_train, idx_val, idx_test = load_dataset( str(args.classifydir.split("/")[-1])) # print(idx_train) # print(type(idx_train)) idx_train = list(idx_train) # idx_val = list(idx_val) # idx_val += list(idx_test)[:600] idx_test = list(idx_test) #[600:] # for i in idx_val: # idx_train.append(i) # idx_val = idx_val[400:] print("TRAINING SIZE", len(idx_train), "VALIDATION SIZE", len(idx_val), "TESTING SIZE: ", len(list(idx_test))) scores = clf.split_train_evaluate_idx(X, Y, idx_train, idx_val) # scores = clf.split_train_evaluate(X, Y, args.train_percent) test_scores = clf.split_train_evaluate_idx(X, Y, idx_train, idx_test) test_x.append(test_scores['macro']) print("micro:", test_scores['micro'], "macro:", test_scores['macro']) return scores
def main(args): t1 = time.time() g = Graph() print("Reading...") if args.graph_format == 'adjlist': g.read_adjlist(filename=args.input) elif args.graph_format == 'edgelist': g.read_edgelist(filename=args.input, weighted=args.weighted, directed=args.directed) g.read_node_label(args.label_file) g.read_node_features(args.feature_file) model = tadw.TADW(graph=g, dim=args.representation_size, lamb=args.lamb) t2 = time.time() print(t2 - t1) print("Saving embeddings...") model.save_embeddings(args.output) vectors = model.vectors X, Y = read_node_label(args.label_file) print("Training classifier using {:.2f}% nodes...".format(args.clf_ratio * 100)) clf = Classifier(vectors=vectors, clf=LogisticRegression()) clf.split_train_evaluate(X, Y, args.clf_ratio)
def node_classification(session, bs, seqne, sequences, seq_len, node_n, samp_idx, label, ratio): enc_sum_dict = {} node_cnt = {} s_idx, e_idx = 0, bs while e_idx < len(sequences): batch_enc = session.run(seqne.encoder_output, feed_dict={seqne.input_seqs: sequences[s_idx: e_idx], seqne.dropout: 0, seqne.keep_prob: 0}) enc_sum_dict, node_cnt = reduce_seq2seq_hidden_add(enc_sum_dict, node_cnt, sequences, batch_enc.astype('float32'), seq_len, s_idx) s_idx, e_idx = e_idx, e_idx + bs if s_idx < len(sequences): batch_enc = session.run(seqne.encoder_output, feed_dict={seqne.input_seqs: sequences[s_idx: len(sequences)], seqne.dropout: 0, seqne.keep_prob: 0}) enc_sum_dict, node_cnt = reduce_seq2seq_hidden_add(enc_sum_dict, node_cnt, sequences, batch_enc.astype('float32'), seq_len, s_idx) node_enc_mean = reduce_seq2seq_hidden_avg(sum_dict=enc_sum_dict, count_dict=node_cnt, node_num=node_n) lr = Classifier(vectors=node_enc_mean, clf=LogisticRegression()) f1_micro, f1_macro = lr.split_train_evaluate(samp_idx, label, ratio) return f1_micro
def train(self, domain, class_data): document = xml.dom.minidom.Document() node = document.createElement('Tree') document.appendChild(node) d = Trainer(domain, class_data, document) partial_atts = d.attributes partial_atts.remove("Id") partial_atts.remove("Vote") print partial_atts if len(self.restr) > 0: d.rem_restrictions(self.restr) d.c45(d.data, d.attributes, node, 0) self.classifier = Classifier() if len(class_data.category) > 0: self.classifier.has_category = True for row in d.data: self.classifier.classify(document.documentElement, row, class_data.attributes) self.classifier.print_stats()
def initialize(self, conf, ctx): self.counter = 0 self.pid = os.getpid() self.total = 0 self.classifier = Classifier() self.directory = str(os.getcwd()) + "/Tweet_Images" if not os.path.exists(self.directory): os.makedirs(self.directory)
def __init__(self, graph, rep_size=128, batch_size=1000, epoch=10, negative_ratio=5, order=3, label_file = None, clf_ratio = 0.5, auto_stop = True): self.rep_size = rep_size self.order = order self.best_result = 0 self.vectors = {} if order == 3: self.model1 = _LINE(graph, rep_size/2, batch_size, negative_ratio, order=1) self.model2 = _LINE(graph, rep_size/2, batch_size, negative_ratio, order=2) for i in range(epoch): self.model1.train_one_epoch() self.model2.train_one_epoch() if label_file: self.get_embeddings() X, Y = read_node_label(label_file) # print "Training classifier using {:.2f}% nodes...".format(clf_ratio*100) clf = Classifier(vectors=self.vectors, clf=LogisticRegression()) result = clf.split_train_evaluate(X, Y, clf_ratio) if result['micro'] < self.best_result and auto_stop: self.vectors = self.last_vectors print 'Auto stop!' return elif result['micro'] > self.best_result: self.best_result = result['micro'] else: self.model = _LINE(graph, rep_size, batch_size, negative_ratio, order=self.order) for i in range(epoch): self.model.train_one_epoch() if label_file: self.get_embeddings() X, Y = read_node_label(label_file) # print "Training classifier using {:.2f}% nodes...".format(clf_ratio*100) clf = Classifier(vectors=self.vectors, clf=LogisticRegression()) result = clf.split_train_evaluate(X, Y, clf_ratio) if result['micro'] < self.best_result and auto_stop: self.vectors = self.last_vectors print 'Auto stop!' return elif result['micro'] > self.best_result: self.best_result = result['micro'] self.get_embeddings()
def classify(vectors, args): if not os.path.isfile(args.classifydir + '_labels.txt'): return defaultdict(lambda: 0) X, Y = read_node_label(args.classifydir + '_labels.txt') print("Training classifier using {:.2f}% nodes...".format( args.train_percent * 100)) clf = Classifier(vectors=vectors, clf=LogisticRegression(solver="lbfgs", max_iter=4000)) scores = clf.split_train_evaluate(X, Y, args.train_percent) return scores
def main(argv): # Constants for the analyzer and the classifier dataset = 'commit_comments-dump.2015-01-29.json' group = 'id' model_file = 'model.pickle' # Create the analyzer analyzer = Analyzer(group) # Create the classifier algorithm_class = RandomForestRegressor algorithm_parameters = { 'n_estimators': 100, 'n_jobs': 2, 'min_samples_split': 10 } classifier = Classifier(group, model_file) classifier.create_model(train=True, class_name=algorithm_class, parameters=algorithm_parameters) # Compare analyzer output with classifier output and identify differences unrecognized_negative = {} unrecognized_positive = {} predictions = classifier.predict() line = 0 # Dataset line i = 0 # Prediction ID (+1) file = open(dataset, 'rb') for data in Utilities.read_json(file, 'id', group): line = line + 1 if line % 1000 == 0: print(line) if not classifier.filter(data): continue i = i + 1 message = data['message'] score = analyzer.analyze(message)[0] if score == 0: continue diff = predictions[i - 1] - score if abs(diff) < 1.0: continue target = unrecognized_negative if diff < 0 else unrecognized_positive target[line] = diff result = sorted(unrecognized_positive.items(), key=lambda x: x[1]) for item in result: print("{}: {}: {}".format(item[0], item[1], linecache.getline(dataset, item[0])[:-1]))
def test_1NN(digitsdat, selected, all_test_m): for testm in all_test_m: classifier = Classifier() # model = build(digitsdat.X[selected[0:testm], :], digitsdat.y[selected[0:testm]]) classifier.build_model(digitsdat.X[selected[0:testm], :], digitsdat.y[selected[0:testm]]) error = classifier.classify(digitsdat.testX, digitsdat.testy) # accuracy = res(model) # print("m=%d error=%f" % (testm, 100-accuracy)) print("m=%d error=%f" % (testm, error)) # global M, e M.append(testm) e.append(error)
def main(args): node_embeddings = load_embeddings(args.embedding_file) if args.label_file: labels = read_node_label(args.label_file) if args.modularity: print("Modularity") modularity(args, node_embeddings, args.min_k, args.max_k) if args.reconstruction: print("Graph reconstruction") reconstr(args, node_embeddings, args.k_nbrs) if args.clustering: print("Clustering") clustering(node_embeddings, labels, args.exp_times) if args.link_prediction: print("Link prediction") link_prediction(args.input, node_embeddings) if args.classification: X = list(labels.keys()) Y = list(labels.values()) print("Node classification") clf_ratio_list = args.clf_ratio.strip().split(',') result_list = {} train_ratio = np.asarray(range(1, 10)) * .1 for clf_ratio in train_ratio: # clf_ratio_list: result_per_test = [] for ti in range(args.exp_times): clf = Classifier(vectors=node_embeddings, clf=LogisticRegression()) myresult = clf.split_train_evaluate(X, Y, float(clf_ratio)) result_per_test.append(myresult) result_list[clf_ratio] = result_per_test print('-------------------') for clf_ratio in train_ratio: print('Train percent:', clf_ratio) results = result_list[clf_ratio] for index, result in enumerate(results): print('Shuffle #%d: ' % (index + 1), result) avg_score = defaultdict(float) for score_dict in results: for metric, score in score_dict.items(): avg_score[metric] += score for metric in avg_score: avg_score[metric] /= len(results) print('Average score:', dict(avg_score)) print('-------------------')
def __init__(self, thread_name, event): super(Controller, self).__init__() self.name = thread_name self.threadEvent = event self.logger_info = utils.initlog('Console', 'Console.log') self.schedule = sched.scheduler(time.time, time.sleep) self.profiles_name, profiles = utils.load_profiles('profiles') self.related_tweets = [[] for _ in range(len(profiles))] self.pushed_tweets = [[] for _ in range(len(profiles))] self.pushed_tweets_ids = set([]) self.related_tweets_hash = set([]) self.classifier = Classifier() self.ranker = self.load_ranker() self.pusher = Pusher()
def node_classification( embeddings, label_path, name, size): X, Y = read_node_label( embeddings, label_path,) f_c=open('results/%s_classification_%d.txt'%(name, size), 'w') all_ratio=[] for tr_frac in [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]: print(" Training classifier using {:.2f}% nodes...".format(tr_frac * 100)) clf = Classifier(embeddings=embeddings, clf=LogisticRegression(), name=name) results= clf.split_train_evaluate(X, Y, tr_frac) avg='macro' f_c.write(name+' train percentage: '+ str(tr_frac)+ ' F1-'+avg+ ' '+ str('%0.5f'%results[avg])) all_ratio.append(results[avg]) f_c.write('\n')
def prepare_data(filename): """ Parse and classify text from file with given filename to prepare data to generate the report. """ parser = Parser() classifier = Classifier() class_duration = { # Dictionary for duration of each class 'W': timedelta(hours=0, minutes=0), 'R': timedelta(hours=0, minutes=0), 'N': timedelta(hours=0, minutes=0), } action_durations = {} # Dictionary for duration of each action activities = parser.parse_file(filename) for activity in activities: duration = activity['duration'] actions = activity['actions'] divided_duration = duration / len(actions) for action in actions: classification = classifier.classify_action(action) class_duration[classification] += divided_duration if action in action_durations: action_durations[action] += divided_duration else: action_durations[action] = divided_duration sorted_action_durations = sorted(action_durations.items(), key=lambda tup: tup[1], reverse=True) # Add structure to data and return plot_data = { 'summary_pie_chart': { 'class_duration': class_duration, }, } report_data = { 'sorted_action_durations': sorted_action_durations, 'class_duration': class_duration, 'timedelta_to_string': timedelta_to_string, } return plot_data, report_data
def evaluate_embeddings_with_split(vectors, X_train, Y_train, X_test, Y_test, Y_all, testnum=10): print("Training classifier with the pre-defined split setting...") #clf = Classifier(vectors=vectors, clf=LogisticRegression()) clf = Classifier(vectors=vectors, clf=SVC(probability=True)) micro_list = [] macro_list = [] for i in range(testnum): res = clf.evaluate_with_fixed_split(X_train, Y_train, X_test, Y_test, Y_all) micro_list.append(res['micro']) macro_list.append(res['macro']) return mean(micro_list), mean(macro_list)
def main(args): print("xnetmf", "begin...") t1 = time.time() print("Reading...") nx_graph = nx.read_edgelist(agrs.input, nodetype=int, comments="%") adj_matrix = nx.adjacency_matrix(nx_graph).todense() print(adj_matrix) g = Graph(adj_matrix) rep_method = RepMethod( max_layer=2 ) # Learn representations with xNetMF. Can adjust parameters (e.g. as in REGAL) representations = src.xnetmf.get_representations(g, rep_method) print(representations) print(representations.shape) print("TAWD", "begin...") print("Reading...") if args.graph_format == 'adjlist': g.read_adjlist(filename=args.input) elif args.graph_format == 'edgelist': g.read_edgelist(filename=args.input, weighted=args.weighted, directed=args.directed) g.read_node_label(args.label_file) g.read_node_features(args.feature_file) model = xtadw.TADW(graph=g, dim=args.representation_size, lamb=args.lamb) t2 = time.time() print(t2 - t1) print("Saving embeddings...") model.save_embeddings(args.output) vectors = model.vectors X, Y = read_node_label(args.label_file) print("Training classifier using {:.2f}% nodes...".format(args.clf_ratio * 100)) clf = Classifier(vectors=vectors, clf=LogisticRegression()) clf.split_train_evaluate(X, Y, args.clf_ratio)
from classify import Classifier cl = Classifier() print(cl.classify('./test/'))
import pickle from mailbox import Client, MessageHandler from colorfind import colorfind, loadScalars, connComps from sys import argv from coords import avg, mul, toInt, split, diff, from_cv2_to_mm_centered from classify import Classifier cap = cv2.VideoCapture(1) cap2 = cv2.VideoCapture(2) host = '192.168.43.83' port = 6164 # fix number msg = [0] n = 0 stop_event = threading.Event() # cap.set(cv2.CAP_PROP_POS_MSEC, 15000) nn = Classifier() def nothing(x): return x def sign(x): if x > 0: return 1. elif x < 0: return -1. elif x == 0: return 0. else: return x
# # results_file = open('0127_best_result_wiki.txt', 'w') # results_file.write(" %s\n" % best_result) # # np.savetxt('best_result_wiki.out', best_result, delimiter='\t') # X is an array clf_list = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] node_size = len(vectors) train_x = np.array([vectors[x] for x in X]) reshaped_train_x = train_x.reshape((train_x.shape[0], args.kstep, node_size)) train_x = low_encoder.predict(reshaped_train_x) for clf_one in clf_list: print "Training classifier using {:.2f}% nodes...".format(clf_one * 100) clf = Classifier(vectors=train_x, clf=LogisticRegression()) clf.split_train_evaluate(X, Y, clf_one) # y_lable = np.array(Y) # print(train_x.shape) # print(type(train_x)) # print(type(y_lable)) # # np.savetxt('train_x.out', train_x, delimiter='\t') # X is an array # np.savetxt('train_Y.out', y_lable.astype(int), delimiter='\t') # X is an array # # # print(results) # results_file = open('citeseer_result_0.3.txt', 'w') # for item in results: # results_file.write("%s\n" % item)
if len(sys.argv) > 3 or len(sys.argv) < 2: print("Please Enter valid parameter:") print("Parameter: Congress term number") print("Option: --skip, avoid data cleaning") sys.exit() if len(sys.argv) == 2: congress_id = str(sys.argv[1]) if os.path.isfile("rawData/" + "speeches_" + congress_id + ".txt") and os.path.isfile("rawData/" + congress_id + "_SpeakerMap.txt"): print("cleaning ....") data_cleaner = Cleaner([congress_id]) data_cleaner.clean_pipeline() print("classifying ....") congress_classifier = Classifier([congress_id]) congress_classifier.base_pipeline() print("done.") sys.exit() else: print( "There are no speeches and speakerMap text file to process for congress " + congress_id) print( "Please put the target congress raw text data into rawData directory" ) sys.exit() if len(sys.argv) == 3 and (sys.argv[1] == "--skip" ): # skip data cleaning (data is already cleaned) congress_id = str(sys.argv[2])
# # main # rec.start_recording() # initialise the tts speech engine engine = pyttsx3.init() # initialise Math class calculator = Computation() # initialise Classifier to find the right command Path classifier = Classifier() print('Please Speak now') while True: samples = rec.get_samples() audio, finalize = vad.process_audio(samples) if not audio: continue logging.debug('decoding audio len=%d finalize=%s audio=%s' % (len(audio), repr(finalize), audio[0].__class__)) user_utt, confidence = asr.decode(audio, finalize, stream_id=STREAM_ID)
import logging # :: Logging level :: loggingLevel = logging.INFO logger = logging.getLogger() logger.setLevel(loggingLevel) ch = logging.StreamHandler(sys.stdout) ch.setLevel(loggingLevel) formatter = logging.Formatter('%(message)s') ch.setFormatter(formatter) logger.addHandler(ch) parser = argparse.ArgumentParser() parser.add_argument('--dataset', help='Location of word dataset files', type=str, required='true') parser.add_argument('--BIO', help='State if its bio_tag', type=bool, default=False) args = parser.parse_args() # Build the graph pmi = PMI(args.dataset) connected = pmi.build_graph() # Performs classification classifier = Classifier(args.dataset, args.BIO) classifier.classify()
def main(argv): folds = int(argv[0]) if len(argv) > 0 else 5 filter = argv[1].lower() if len(argv) > 1 else "" # Fields to check whether the filter, if given, appears in. filter_fields = ['name', 'class_name', 'module'] # Read the manifest containing algorithm descriptions. with open('algorithms.json', 'r') as manifest: algorithms = json.load(manifest) # Load previous results try: with open('experiment_results.json', 'r') as file: results = json.load(file) except: results = {} for algorithm in algorithms: # Skip running the algorithm if it is disabled or the filter name does # not appear in any of the fields. if 'disabled' in algorithm and algorithm['disabled']: continue if filter and all( [filter not in algorithm[k].lower() for k in filter_fields]): continue # Convert manifest entries to classifier class and parameters class_name = Utilities.get_class(algorithm['module'], algorithm['class_name']) dense = algorithm['dense'] if 'dense' in algorithm else False # Create all possible combinations of parameters. parameter_combinations = itertools.product( *algorithm['parameters'].values()) single_parameters = [ param for param, values in algorithm['parameters'].iteritems() if len(values) == 1 ] string_parameters = [ param for param, values in algorithm['parameters'].iteritems() if isinstance(values[0], (str, unicode)) ] for combination in parameter_combinations: classifier = Classifier('id') # Turn the selected parameter combination back into a dictionary parameters = dict(zip(algorithm['parameters'].keys(), combination)) # Create the model according to the parameters classifier.create_model(train=False, class_name=class_name, parameters=parameters, dense=dense) Utilities.print_algorithm(algorithm['name'], parameters) parameter_string = Utilities.get_parameter_string( parameters, single_parameters + string_parameters) # Run cross-validation and print results result = classifier.output_cross_validate(folds) print('') name = algorithm['name'] for param in string_parameters: name += ", %s=%s" % (param, parameters[param]) # Write the result measurements into the results dictionary. if name not in results: results[name] = OrderedDict() results[name].update({ parameter_string: { 'average': result.mean(), 'standard_deviation': result.std() } }) # Write intermediate results (back) into a pretty-printed JSON file with open('experiment_results.json', 'w') as file: json.dump(results, file, indent=4, separators=(',', ': '))
import io import numpy as np from torch import nn import torch.utils.model_zoo as model_zoo import torch.onnx import onnxruntime import cv2 from classify import Classifier, get_default_args if __name__ == '__main__': cfg = get_default_args() classify = Classifier(cfg) torch_model = classify.model torch_model.to(torch.device('cpu')) x = torch.randn(1, 3, 224, 224) frame = cv2.imread('/home/cmf/datasets/spoof/NUAADetectedface/Detectedface/ImposterFace/0001/0001_00_00_01_0.jpg') img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) img = cv2.resize(img, (224, 224)) # img = np.float32(img) img = img.astype(np.float32) # print(img.max(), img.min()) img = img / 255 # print(img.max(), img.min()) img = np.transpose(img, (2, 0, 1))
from threading import Thread import time import collections from pprint import pprint as pp import csv import pickle from classify import Classifier import os from listdir import DirAsXML username = "" cur_path = "" model_path = 'news20.gensim' dict_name = 'dictionary20' c = Classifier(model_path, dict_name) def move_file(cur_path, new_path): """move file from old path to new path""" try: os.rename(cur_path, new_path) except FileExistsError: filename, file_extension = os.path.splitext(new_path) new_path = filename + "(1)" + file_extension move_file(cur_path, new_path) def accept_incoming_connections(): """Sets up handling for incoming clients.""" while True:
# -*- coding: utf-8 -*- from classify import Classifier import urllib clf = Classifier() clf.load_image("/home/hari/Documents/Big_data/bits-please/car.jpg") predicted_class = clf.classify() print (" ".join(predicted_class))
break elif file_mode == 'w+': friends_file = open(complete_name, 'w+') print("enter the names of your FB contacts [Ctrl-D to save it]: ") while True: try: line = input() except EOFError: break friends_file.write('%r\n' %line) break else: print('incorrect input, please try again\n') friends_file.seek(0) c = Classifier() from_lengths = {} to_lengths = {} from_sentiments = {} to_sentiments = {} friends = [] for l in friends_file: a,b = l.split(" ") friend_name = a + ' ' + b friends.append(friend_name) for friend_name in friends: print(friend_name)
def main(args): print("number-walks " + str(args.number_walks)) print("representation-size " + str(args.representation_size)) print("walk-length " + str(args.walk_length)) print("inout_fle " + str(args.input)) print("******") g = Graph() deepw = False #similarity thresholds for compration trsl = [0.45, 0.495, 0.5, 0.55, 0.6, 0.7, 0.8, 1] # trsl=[ 0.5 ] learn = True X, Y = read_node_label(args.label_file) seed = 0 clsratio = [0.01, 0.05, 0.07, 0.1, 0.25, 0.5, 0.7, 0.8] # clsratio=[ 0.1,0.2,0.4, 0.6,0.7,0.8,0.9]#,0.7,0.8]# use for blogcatalog np.random.seed(seed) shuffle_indices = np.random.permutation(np.arange(len(X))) f = open(args.input + "shu.txt", "w") f.writelines(str(item) + "\n" for item in shuffle_indices) f.close() if args.graph_format == 'adjlist': g.read_adjlist(filename=args.input, directed=args.directed) elif args.graph_format == 'edgelist': g.read_edgelist(filename=args.input, weighted=args.weighted, directed=args.directed) G = g.G print("before spar, n: " + str(len(G.nodes())) + " m: " + str(len(G.edges()))) #compute similarity score for compression t1 = time.time() p = pC(G, 0.45) scoreNode = p.ScoreCompute() t3 = time.time() f = open(args.input + "score.txt", "w") f.writelines( str(n[0]) + " " + str(n[1]) + " " + str(scoreNode[n]) + "\n" for n in scoreNode) f.close() print("total scorecom time: " + str(t3 - t1)) # read similarity scores from file # f=open(args.input+"score.txt","r") # scoreNode=dict() # for x in f: # l=x.split() # scoreNode[((l[0]),(l[1]))] = float(l[2]) for kk in range(0, len(trsl)): if learn: # do embeding ths = trsl[kk] #args.trs print("threshold is ...", ths) if args.graph_format == 'adjlist': g.read_adjlist(filename=args.input, directed=args.directed) elif args.graph_format == 'edgelist': g.read_edgelist(filename=args.input, weighted=args.weighted, directed=args.directed) if ths != 1: #compression t1 = time.time() G = g.G G, nl2 = makeCompression(G, scoreNode, ths) f = open(args.input + "af_spar.txt", "w") f.writelines(str(n) + " " + str(nl2[n]) + "\n" for n in nl2) f.close() writeg(G, args) t2 = time.time() print("total_sparc_time: " + str(t2 - t1)) #embedding t1 = time.time() print("After_compresing,n,m " + str(len(g.G.nodes())) + " " + str(len(g.G.edges()))) model = node2vec.Node2vec(graph=g, path_length=args.walk_length, num_paths=args.number_walks, dim=args.representation_size, workers=args.workers, p=args.p, q=args.q, window=args.window_size, dw=deepw) t2 = time.time() print("total_embeding_time " + str(t2 - t1)) vectors = model.vectors if ths != 1: #add embedding of removed nodes in compression addBack(nl2, vectors) np.save(args.output + "_" + str(ths) + ".npy", vectors) else: #load embeddings vectors = np.load(args.output + "_" + str(ths) + ".npy") vectors = vectors.item(0) print("file_loaded") #print("Training classifier") #split_train_evaluate2 for single label (cora and wiki) #split_train_evaluate for multi lable (dblp and blogcatalog) for r in clsratio: clfa = Classifier(vectors, clf=LogisticRegression(solver='liblinear')) res = clfa.split_train_evaluate2( X, Y, r, shuffle_indices) # args.clf_ratio) print(str(r) + " " + str(res["macro"]) + " " + str(res["micro"]))
from detector import LicensePlateDetector, VehicleDetector from vin import VIN from licenseplate import LicensePlate from detect_angle import detect_angle import html from misc.switch import switch #from os import listdir from os.path import exists #,isfile, join app = Flask(__name__) #, static_folder='static', static_url_path='') UPLOAD_FOLDER = 'uploads' WEBFILE_FOLDER = 'webfiles' app.qualityanalyzer = AnalyzeImageQuality() app.classifier = Classifier() app.detector = VehicleDetector() app.licenseplatedetector = LicensePlateDetector() app.licenseplate = LicensePlate() app.vehicleidentifier = VIN() app.results = [] app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['WEBFILE_FOLDER'] = WEBFILE_FOLDER app.config["CACHE_TYPE"] = "null" app.config['ALLOWED_EXTENSIONS'] = set( ['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) app.config['MAX_CONTENT_LENGTH'] = 3 * 1024 * 1024 # 1 Mb limit app.image_fn = os.path.join(app.config['UPLOAD_FOLDER'], "image.jpg") app.result_fn = os.path.join(app.config['UPLOAD_FOLDER'], "result.txt") app.filename = ""