Ejemplo n.º 1
0
from logzero import logger

from models import *
from tpod_models import *
import shutil
from vatic import merge
import velocity
import util
import xml.etree.ElementTree as ET
from vision import ffmpeg
import m_logger
from extensions import db
import dumptools
import db_helper

logger = m_logger.get_logger(os.path.basename(__file__))


def delete_video(video_id):
    session = db.session
    video = session.query(Video).filter(Video.id == video_id).first()
    if video:
        # delete original file
        original_file_path = video.orig_file_path
        if os.path.exists(original_file_path):
            os.remove(original_file_path)

        # delete extract file
        extract_file_path = video.extract_path
        if os.path.exists(extract_file_path):
            shutil.rmtree(extract_file_path)
Ejemplo n.º 2
0
#-*- coding: utf-8 -*-
"""
* Purspose : Manage conf files - for any purpose about conf file structure please check python doc.
* Author : Meriadoc
* Log :
    * 05/08/2019 : PB : Initial commit
    * 09/08/2019 : PB : update get_section error management
"""

import m_logger as log
import configparser
import os

logger = log.get_logger('conf', log.get_logger_level('warning'))
"""
* Purpose : return a dict of a section conf
* Raise :
    * TypeError
    * IOError
    * NameError
    * UnicodeError
* In : 
    * file_name : name of the file conf
    * path : where is stored the conf file
    * section : the conf section name that you are looking for
* Out :
    * dict with all the conf param of the section
"""


def get_section(file_name, path, section):
Ejemplo n.º 3
0
from tpod_models import User, Video, Classifier
from forms import *
from flask_superadmin import Admin, model, AdminIndexView
from flask import jsonify
from video_blueprint import video_page
from label_blueprint import label_page
from classifier_blueprint import classifier_page
from flask_bootstrap import Bootstrap
import response_util
from flask_sqlalchemy import SQLAlchemy
import os
from flask_migrate import MigrateCommand
from extensions import db, login_manager, migrate, manager
import m_logger

logger = m_logger.get_logger('LOGIN_PAGE')

app = Flask(__name__, static_url_path='/static', template_folder='/templates')
app.register_blueprint(vatic_page)
app.register_blueprint(video_page)
app.register_blueprint(label_page)
app.register_blueprint(classifier_page)

#### plugin db
db_user = os.environ.get('DB_USER', 'tpod')
db_name = os.environ.get('DB_NAME', 'tpod')
db_password = os.environ.get('DB_PASSWORD', 'none')
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://{}:{}@localhost/{}".format(
    db_user, db_password, db_name)

db.init_app(app)
Ejemplo n.º 4
0
"""
* Purpose : manage file interaction
* Author : Meriadoc
* Log :
    * 05/08/2019 : Initial commit
    * 08/08/2019 : Update append fct : remove index = false
    * 08/08/2019 : update with error_bad_lines in fct csv to df
    * 11/09/2019 : Add df cleaner
"""

import m_logger as log
import pandas as pd
import os

logger = log.get_logger('file', log.get_logger_level('warning'))
"""
* Purpose : get a csv file stored on the disk and return a dataframe
* In :
    * file path
    * file name
* Out :
    * panda dataframe
"""


def csv_to_df(path, file_name):

    if not isinstance(path, str):
        logger.error('path : String require')
        return False
Ejemplo n.º 5
0
import shutil
from forms import DeleteVideoForm, ExportVideoForm
import response_util
import import_label
#import export_label
from flask import send_file
import json

video_page = Blueprint('video_page',
                       __name__,
                       url_prefix='/video',
                       template_folder='templates',
                       static_url_path='/static',
                       static_folder='static')

logger = m_logger.get_logger('VIDEO_PAGE')


@video_page.route("/index", methods=["GET"])
@login_required
def index():
    return render_template('index_video.html')


@video_page.route("/list", methods=["GET"])
@login_required
def list_video():
    videos = db_helper.get_videos_of_user(current_user.id)
    # sort videos by name
    videos = sorted(videos, key=lambda x: x['name'])
    print 'get %s videos for user %s ' % (str(len(videos)), str(
Ejemplo n.º 6
0
# See the License for the specific language governing permissions and
# limitations under the License.

from flask import Blueprint, render_template, abort
from flask_login import LoginManager, login_required, login_user, logout_user, current_user
from flask import Flask, request, render_template, redirect, url_for, flash, send_from_directory, send_file, g, abort, Response
from vatic.models import *
import response_util
import m_logger
from forms import AddLabelForm, DeleteLabelForm, EditLabelForm
from vatic import turkic_replacement

from extensions import db

label_page = Blueprint('label_page', __name__, url_prefix='/label')
logger = m_logger.get_logger('LABEL_PAGE')


@label_page.route("/delete", methods=["POST"])
@login_required
def delete_label():
    form = DeleteLabelForm(request.form)
    if form.validate():
        label = Label.query.filter(Label.id == form.label_id.data).first()
        video = Video.query.filter(Video.id == label.videoid).first()
        video.labels.remove(label)
        label.delete()
        db.session.commit()
        return redirect(request.referrer)
    return response_util.json_error_response(msg=str(form.errors))
Ejemplo n.º 7
0
import shutil

import config
import util
from tpod_models import Classifier, EvaluationSet
from vatic.models import Video, Label, Box, Path
from celery_tasks import train_task, test_task, evaluation_task, push_image_task
import random
from celery_model import TaskStatusRecord
from sqlalchemy import desc
from vatic import turkic_replacement
import docker
from extensions import db
import m_logger

logger = m_logger.get_logger('CLASSIFIER_CONTROLLER')


# the basic structure: class is separated by '.' label is separated by ';' coordination is separated by ','
def generate_frame_label(frame_labels):
    if len(frame_labels) == 0:
        return ''
    else:
        line = ''
        # first, travel through all classes
        for ic, item_class in enumerate(frame_labels):
            # then, travel through labels under that class
            if len(item_class) > 0:
                for il, label in enumerate(item_class):
                    str_label = ','.join(label)
                    line += str_label
Ejemplo n.º 8
0
#-*- coding: utf-8 -*-
"""
* Purpose : run web requests
* Author : Meriadoc
* Log :
    * 05/08/2019 : Initial commit
"""

import urllib2
import m_logger as log

logger = log.get_logger('request', log.get_logger_level('warning'))
"""
* Purpose :
* In :
    * the requested url
* Out :
    * string
"""


def request_html(url):

    if not isinstance(url, str):
        logger.error('url : string require')
        return False

    try:
        logger.debug('Get new web page')
        result = urllib2.urlopen(url)
        contents = result.read()
Ejemplo n.º 9
0
#-*- coding: utf-8 -*-
"""
* Purspose : Manage conf files - for any purpose about conf file structure please check python doc.
* Author : Meriadoc
* Log :
    * 05/08/2019 : PB : Initial commit
"""

import m_logger as log
import configparser
import os

logger = log.get_logger('conf', log.get_logger_level('info'))
"""
* Purpose : resturn a dict of a section conf
* In : 
    * file_name : name of the file conf
    * path : where is stored the conf file
    * section : the conf section name that you are looking for
* Out :
    * dict with all the conf param of the section
"""


def get_section_conf(file_name, path, section):

    logger.debug('Start to get conf')

    #San tests
    if not isinstance(file_name, str):
        logger.error('file_name param has to be a string')
Ejemplo n.º 10
0
import hashlib
import subprocess
import re
import pika
import socket
import requests
import time
from functools import wraps, update_wrapper
from datetime import datetime

from flask import make_response

import docker
import m_logger

logger = m_logger.get_logger('UTIL')


def get_file_size(file_name):
    stat = os.stat(file_name)
    return stat.st_size


def get_file_md5(file_name):
    hash_md5 = hashlib.md5()
    with open(file_name, "rb") as f:
        for chunk in iter(lambda: f.read(4096), b""):
            hash_md5.update(chunk)
    return hash_md5.hexdigest()

Ejemplo n.º 11
0
from forms import *
import response_util
import classifier_controller as controller
import json
import config
import time
import random
import util
from flask import send_file
from vatic import turkic_replacement
import parameters
import util

import m_logger

logger = m_logger.get_logger('CLASSIFIER_BLUEPRINT')

classifier_page = Blueprint('classifier_page', __name__, url_prefix='/classifier', template_folder='templates',
                            static_url_path='/static', static_folder='static')


def sol_jsonify(labels):
    '''
    Convert labels to sol format json
    '''
    ret = []
    for label in labels:
        obj = {
            'type': 'option',
            'label': '%s (%s frames, from video %s)' % (
                label['name'], str(label['labeled_frame']), label['video_name']),