def run_exp_for_classifier(classifier_file, save_dir=DIR_CLASSIFIERS): from app import get_api api = get_api() full_classifier_path = DIR_CLASSIFIERS + classifier_file clf = load_saved_classifier(full_classifier_path) file_name = clf.video_path.split("/")[-1] # Include c type & params fp = save_dir + STR_PARAM_DELIM.join( [classifier_file, "SSTRATE", "EXP", file_name, str(time.clock()), ".csv"] ) exp = EXPMLVidSubstrateFullFrame(clf.ground_truth, clf.video_path, None, classifier=clf, init=False) c_hash = hash(classifier_file) # Unique ID for log tracking log.info("Testing Classifier: {} Hash: {} Video: {}".format( classifier_file, c_hash, clf.video_path )) training_frames = set(clf.training_data) # The frames used to train results = [] for klass in exp.classes: log.info("{}: Testing class {} begins.".format(c_hash, klass)) start_time = datetime.datetime.now() class_frames = set(exp.ground_truth.get_frames_for_class(klass)) testing_frames = class_frames.difference(training_frames) # Deconstruct the filename c to get the method function_name = classifier_file.split(STR_PARAM_DELIM)[-2] function_ptr = api.methods.get_function_ptr(function_name) # This seems like a nice candidate for parellisation # We have n_frames and n_procs. Split n_frames / n_procs and allocate for f in testing_frames: exp.converter.set_current_frame(f) exp.converter.capture_next_frame() frame = exp.converter.current_frame for element in exp.get_data_from_frame(frame): # So this can be a full frame, or a window, or anything really... # Just needs to be consistent with the original exp data = function_ptr(element) if isinstance(data, np.ndarray): data = data.ravel() result = exp.classifier.classify(data) # Get the result results.append([f, klass, result[0], int(klass) == int(result)]) time_delta = datetime.datetime.now() - start_time log.info("{}: Testing class {} finishes (taken: {})".format( c_hash, klass, time_delta )) with CSVEXPSubstrateWriter(fp, c_hash, clf) as csv_file: map(lambda x: csv_file.writerow(x), results) os.rename(full_classifier_path, full_classifier_path + ".npy")
import re from flask import g from flask_restplus import marshal_with, fields, Resource, reqparse from app import db, get_api from app.api.v1.common.exception.exceptions import AccountException, CommonException from app.api.v1.common.views import ResponseWrapper from app.api.v1.users.models import User from app.api.v1.authentications.authentication import auth api = get_api() user_field = { 'id': fields.Integer, 'status': fields.String(attribute=lambda x: x.status.name), 'username': fields.String, 'university': fields.String, 'email': fields.String } user_register_parser = reqparse.RequestParser() user_register_parser.add_argument('username') user_register_parser.add_argument('email') user_register_parser.add_argument('password') @api.route('/users/<int:user_id>') class UserSearchApi(Resource): decorators = [auth.login_required]
help="Execute a specific experiment JSON file (Path required)") parser.add_argument("-v", "--version", help="Prints Neptune version", action="store_true") if __name__ == '__main__': import logging logger = logging.getLogger(__name__) args = parser.parse_args() if args.version: print(config.APP_VERSION) elif args.api: from app import get_api API = get_api() for api_element in API.structure: print(api_element) elif args.apiversion: from app import get_api API = get_api() print(API.version) elif args.experiment: from experiments.holder import EXPHarnessLoader exp = EXPHarnessLoader.get_exp_for(args.experiment) exp.run() if args.runexp: from experiments.videolearning import EXPClassifierHandler EXPClassifierHandler.run_exp_for_all_classifiers() elif args.runexp:
__author__ = 'matt' KEY_DESCR = "description" KEY_CLASS = "experiment" # JSON specific keys KEY_ALLFUNC = "allFunctions" KEY_EXPTYPE = "experimentType" KEY_EXPARGS = "experimentArgs" KEY_SELFUNC = "selectedFunctions" KEY_ALLCLAS = "allClassifiers" KEY_SELCLAS = "selectedClassifiers" KEY_SELVIDS = "selectedVideos" KEY_SELEXPS = "selectedExperiment" API = get_api() def get_exp_harness(json_file): exp_json = load_json(json_file) if KEY_EXPTYPE in exp_json: klass = API_MAP[exp_json[KEY_EXPTYPE]][KEY_CLASS] exp = klass(exp_json) else: exp = None return exp def train_classifier(tasks, results): for exp_tuple in iter(tasks.get, None):
def run_exp_for_classifier(classifier_file, save_dir=DIR_CLASSIFIERS): from app import get_api api = get_api() full_classifier_path = DIR_CLASSIFIERS + classifier_file clf = load_saved_classifier(full_classifier_path) file_name = clf.video_path.split("/")[-1] # Include c type & params fp = save_dir + STR_PARAM_DELIM.join([ classifier_file, "SSTRATE", "EXP", file_name, str(time.clock()), ".csv" ]) exp = EXPMLVidSubstrateFullFrame(clf.ground_truth, clf.video_path, None, classifier=clf, init=False) c_hash = hash(classifier_file) # Unique ID for log tracking log.info("Testing Classifier: {} Hash: {} Video: {}".format( classifier_file, c_hash, clf.video_path)) training_frames = set(clf.training_data) # The frames used to train results = [] for klass in exp.classes: log.info("{}: Testing class {} begins.".format(c_hash, klass)) start_time = datetime.datetime.now() class_frames = set(exp.ground_truth.get_frames_for_class(klass)) testing_frames = class_frames.difference(training_frames) # Deconstruct the filename c to get the method function_name = classifier_file.split(STR_PARAM_DELIM)[-2] function_ptr = api.methods.get_function_ptr(function_name) # This seems like a nice candidate for parellisation # We have n_frames and n_procs. Split n_frames / n_procs and allocate for f in testing_frames: exp.converter.set_current_frame(f) exp.converter.capture_next_frame() frame = exp.converter.current_frame for element in exp.get_data_from_frame(frame): # So this can be a full frame, or a window, or anything really... # Just needs to be consistent with the original exp data = function_ptr(element) if isinstance(data, np.ndarray): data = data.ravel() result = exp.classifier.classify(data) # Get the result results.append( [f, klass, result[0], int(klass) == int(result)]) time_delta = datetime.datetime.now() - start_time log.info("{}: Testing class {} finishes (taken: {})".format( c_hash, klass, time_delta)) with CSVEXPSubstrateWriter(fp, c_hash, clf) as csv_file: map(lambda x: csv_file.writerow(x), results) os.rename(full_classifier_path, full_classifier_path + ".npy")