Ejemplo n.º 1
0
def record_result(record_time):
    print record_time
    record_time_filename = (record_time.replace(' ', '_')).replace(':', '~')
    record_file = os.path.join(app.config['UPLOAD_FOLDER'], record_time_filename)
    result_folder = os.path.join(record_file, RESULT_FOLDER)
    video_list = []
    with open(os.path.join(result_folder, result_handler.COMPARISON_FILE)) as fh:
        lines = fh.readlines()
        for line in lines:
            video = VideoResult()
            line_arr = []
            line_arr = line.strip().split(' ')
            if line_arr.__len__() > 4:
                pos = line_arr.__len__() - 1
                video.score = line_arr[pos]
                video.pre_label = line_arr[pos-1]
                video.ground_truth_label = line_arr[pos - 2]
                for i in range(pos - 2):
                    if i < pos - 2:
                        video.path += line_arr[i] + ' '
                    else:
                        video.path += line_arr[i]
            else:
                video.path, video.ground_truth_label, video.pre_label, video.score = line.strip().split(" ")
            video.ground_truth_label = LABEL[int(video.ground_truth_label)]
            video.pre_label = LABEL[int(video.pre_label)]
            video.name = os.path.basename(video.path)
            video.path = video.path.replace('/', '_')
            video.time = record_time_filename
            video_list.append(video)
        fh.close()
    distributions = []
    with open(os.path.join(result_folder, result_handler.DISTRIBUTION_FILE)) as fh:
        lines = fh.readlines()
        for line in lines:
            distribution = []
            normal_percent, porn_percent, sexy_percent = line.strip().split(' ')
            distribution.append(normal_percent)
            distribution.append(porn_percent)
            distribution.append(sexy_percent)
            distributions.append(distribution)
        fh.close()
    accuracy = ''
    with open(os.path.join(result_folder, result_handler.EVALUATION_FILE)) as fh:
        accuracy = fh.readline().strip().split(' ')[1]
        fh.close()
    return render_template('record_result.html', video_list=video_list,
                           distributions=distributions, accuracy=accuracy, labels=LABEL)
Ejemplo n.º 2
0
def upload():
    # Get the name of the uploaded files
    result_zip_file = request.files['ResultZipFile']
    ground_truth_file = request.files['GroundTruthFile']
    print result_zip_file.filename
    print ground_truth_file.filename
    # filenames = []
    if result_zip_file and allowed_zip_file(result_zip_file.filename) \
            and ground_truth_file and allowed_txt_file(ground_truth_file.filename):
        filename = secure_filename(result_zip_file.filename)
        zip_file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
        result_zip_file.save(zip_file_path)

        ground_truth_filename = secure_filename(ground_truth_file.filename)
        ground_truth_file_path = os.path.join(app.config['UPLOAD_FOLDER'], ground_truth_filename)
        ground_truth_file.save(ground_truth_file_path)

        timestamp = time.strftime('%Y-%m-%d_%H~%M~%S', time.localtime(time.time()))
        zip_file = zipfile.ZipFile(zip_file_path, 'r')
        record_path = os.path.join(app.config['UPLOAD_FOLDER'], timestamp)
        zip_path = os.path.join(record_path, ZIP_FOLDER)
        zip_file.extractall(zip_path)
        folder_list = os.listdir(zip_path)
        zip_file.close()
        video_list = []
        for folder in folder_list:
            args.ground_truth_file = ground_truth_file_path
            args.input_dir = os.path.join(zip_path, folder)
            args.output_dir = os.path.join(record_path, RESULT_FOLDER)

            if os.path.exists(args.output_dir) is not True:
                os.makedirs(args.output_dir)

            result_handler.result_deepir_process(args)
            result_handler.evaluation(args)
            result_handler.distribution(args)
            result_handler.comparison(args)

        result_folder = os.path.join(os.path.join(record_path, RESULT_FOLDER))
        with open(os.path.join(result_folder, result_handler.COMPARISON_FILE)) as fh:
            lines = fh.readlines()
            for line in lines:
                video = VideoResult()
                video.path, video.ground_truth_label, video.pre_label, video.score = line.strip('\n').split(" ")
                video.ground_truth_label = LABEL[int(video.ground_truth_label)]
                video.pre_label = LABEL[int(video.pre_label)]
                video.name = os.path.basename(video.path)
                video.path = video.path.replace('/', '_')
                video.time = timestamp
                video_list.append(video)
            fh.close
        os.remove(os.path.join(os.getcwd(), zip_file_path))
        os.remove(os.path.join(os.getcwd(), ground_truth_file_path))
        distributions = []
        with open(os.path.join(result_folder, result_handler.DISTRIBUTION_FILE)) as fh:
            lines = fh.readlines()
            for line in lines:
                distribution = []
                normal_percent, porn_percent, sexy_percent = line.strip('\n').split(' ')
                distribution.append(normal_percent)
                distribution.append(porn_percent)
                distribution.append(sexy_percent)
                distributions.append(distribution)
            fh.close()
        accuracy = ''
        with open(os.path.join(result_folder, result_handler.EVALUATION_FILE)) as fh:
            accuracy = fh.readline().strip('\n').split(' ')[1]
            fh.close()
    return render_template('upload.html', video_list=video_list,
                           distributions=distributions, accuracy=accuracy, labels=LABEL)