Exemple #1
0
# coding=utf-8
from __future__ import absolute_import, print_function

import os
from pm4py.objects.log.importer.xes import factory as xes_importer
from pm4py.algo.discovery.heuristics import factory as heuristics_miner
from pm4py.visualization.petrinet import factory as pn_vis_factory
from suanpan.app import app
from suanpan.app.arguments import Folder, Float, Int


@app.input(Folder(key="inputData1", alias="inputData"))
@app.param(Float(key="dependencyThresh", default=0.5))
@app.param(Float(key="andMeasureThresh", default=0.65))
@app.param(Int(key="minActCount", default=1))
@app.param(Int(key="minDfgOccurrences", default=1))
@app.param(Float(key="dfgPreCleaningNoiseThresh", default=0.05))
@app.output(Folder(key="outputData1", alias="outputData"))
def SPHeuristicsMiner(context):
    args = context.args
    inputFile = os.path.join(args.inputData, os.listdir(args.inputData)[0])
    log = xes_importer.import_log(inputFile)
    net, im, fm = heuristics_miner.apply(
        log,
        parameters={
            "dependency_thresh": args.dependencyThresh,
            "and_measure_thresh": args.andMeasureThresh,
            "min_act_count": args.minActCount,
            "min_dfg_occurrences": args.minDfgOccurrences,
            "dfg_pre_cleaning_noise_thresh": args.dfgPreCleaningNoiseThresh,
        },
Exemple #2
0
from __future__ import absolute_import, print_function

import os
from suanpan.app.arguments import Folder, Int, Float, Model
from suanpan.app import app
from suanpan.log import logger
from suanpan.utils import json
from arguments import CFGModel


@app.input(Model(key="inputModel", type=CFGModel))
@app.input(Folder(key="inputTrainImage"))
@app.input(Folder(key="inputTrainJson"))
@app.input(Folder(key="inputTestImage"))
@app.input(Folder(key="inputTestJson"))
@app.param(Int(key="__gpu", default=0))
@app.param(Int(key="ImgsPerBatch", default=2))
@app.param(Float(key="BaseLR", default=0.00025))
@app.param(Int(key="MaxIter", default=300))
@app.param(Int(key="BatchSizePerImg", default=128))
@app.param(Int(key="NumWorkers", default=4))
@app.output(Model(key="outputModel", type=CFGModel))
@app.output(Folder(key="outputData"))
def SPTrainer(context):
    args = context.args
    model = args.inputModel
    device = "cuda" if args.__gpu else "cpu"
    logger.info(
        "**********Use {} Device for Training**********".format(device))

    trainImg = args.inputTrainImage
Exemple #3
0
# coding=utf-8
from __future__ import absolute_import, print_function

import os
from suanpan.app.arguments import Folder, String, Int, Float
from suanpan.app import app
from lib import cli


@app.input(Folder(key="inputData"))
@app.param(String(key="detector", default="cv2-dnn",
                  help="cv2-dnn mtcnn s3fd"))
@app.param(String(key="aligner", default="cv2-dnn", help="cv2-dnn fan"))
@app.param(
    String(key="normalization", default="none", help="none clahe hist mean"))
@app.param(Int(key="minSize", default=0, help="(0, 1080)"))
@app.param(Float(key="blurThreshold", default=0.0, help="(0.0, 100.0)"))
@app.output(Folder(key="outputData1"))
@app.output(Folder(key="outputData2"))
def SPExtractFace(context):
    args = context.args

    PARSER = cli.FullHelpArgumentParser()
    EXTRACT = cli.ExtractArgs(PARSER, "extract",
                              "Extract the faces from pictures")

    ARGUMENTS = PARSER.parse_args([
        "--input-dir",
        args.inputData,
        "--output-dir",
        args.outputData1,
Exemple #4
0
from __future__ import absolute_import, print_function

import os
import json
from suanpan.app import app
from suanpan.app.arguments import Folder, ListOfInt, Int
from suanpan.log import logger
from suanpan.utils import image
from suanpan.storage import storage
from arguments import Images


@app.input(Images(key="inputImage"))
@app.input(Folder(key="inputData"))
@app.param(ListOfInt(key="xy", default=[0, 0]))
@app.param(Int(key="x"))
@app.param(Int(key="y"))
@app.output(Images(key="outputImage"))
def SPImageBox(context):
    args = context.args
    images = args.inputImage

    files = []

    try:
        if args.inputData:
            jsonFile = os.path.join(args.inputData, "project.json")
            with open(jsonFile, "rb") as load_f:
                fileInfo = json.load(load_f)

            for i, j in fileInfo["metadata"].items():
Exemple #5
0
# coding=utf-8
from __future__ import absolute_import, print_function

from suanpan.app.arguments import Folder, String, Int
from suanpan.app import app
from mainscripts import VideoEd


@app.input(Folder(key="inputData"))
@app.param(String(key="ext", default="png"))
@app.param(Int(key="factor", default=5))
@app.output(Folder(key="outputData"))
def SPDenoise(context):
    args = context.args

    VideoEd.denoise_image_sequence(args.inputData,
                                   args.outputData,
                                   ext=args.ext,
                                   factor=args.factor)

    return args.outputData


if __name__ == "__main__":
    SPDenoise()
Exemple #6
0
        help=
        "blur, face, face-cnn, face-cnn-dissim, face-yaw, hist, hist-dissim",
    ))
@app.param(
    Float(
        key="refThreshold",
        default=-1.0,
        help="(-1.0, 10.0) Defaults: face-cnn 7.2, hist 0.3",
    ))
@app.param(String(key="finalProcess", default="rename",
                  help="folders, rename"))
@app.param(
    String(key="groupBy",
           default="hist",
           help="blur, face-cnn, face-yaw, hist"))
@app.param(Int(key="bins", default=5, help="(1, 100)"))
@app.output(Folder(key="outputData"))
def SPSort(context):
    args = context.args

    PARSER = FullHelpArgumentParser()
    SORT = cli.SortArgs(
        PARSER, "sort",
        "This command lets you sort images using various methods.")

    ARGUMENTS = PARSER.parse_args([
        "--input",
        args.inputData,
        "--output",
        args.outputData,
        "--sort-by",
Exemple #7
0
# coding=utf-8
from __future__ import absolute_import, print_function

import torch
from suanpan.app.arguments import Folder, Json, Model, Int, Float
from suanpan.app import app
from suanpan.log import logger
from arguments import CFGModel
from utils.tools import find_files


@app.input(Model(key="inputModel", type=CFGModel))
@app.input(Folder(key="inputData"))
@app.param(Int(key="__gpu", default=0))
@app.param(Float(key="ScoreThreshTest", default=0.5))
@app.output(Json(key="outputData1"))
@app.output(Folder(key="outputData2"))
def SPPredictor(context):
    args = context.args
    model = args.inputModel
    device = "cuda" if args.__gpu else "cpu"
    logger.info(
        "**********Use {} Device for Predicting**********".format(device))
    model.device(device)
    model.cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = args.ScoreThreshTest

    fileType = (
        ".jpg",
        ".jpeg",
        ".png",
        ".ppm",
Exemple #8
0
# coding=utf-8
from __future__ import absolute_import, print_function

from suanpan.app.arguments import Folder, String, Int
from suanpan.app import app
from mainscripts import VideoEd
from utils import get_all_files


@app.input(Folder(key="inputData"))
@app.param(String(key="fromTime", default="00:00:00.000"))
@app.param(String(key="toTime", default="00:00:01.000"))
@app.param(Int(key="audioTrackId", default=0))
@app.param(Int(key="bitrate", default=25))
@app.output(Folder(key="outputData"))
def SPCutVideo(context):
    args = context.args

    fileList = get_all_files(args.inputData)

    VideoEd.cut_video(
        fileList[0],
        args.outputData,
        args.fromTime,
        args.toTime,
        args.audioTrackId,
        args.bitrate,
    )

    return args.outputData
Exemple #9
0
# coding=utf-8
from __future__ import absolute_import, print_function

import os
import math
from suanpan.app import app
from suanpan.app.arguments import Int
from suanpan.storage import storage
from suanpan.utils import image
from arguments import Images


@app.input(Images(key="inputImage"))
@app.param(Int(key="x", default=100))
@app.param(Int(key="y", default=100))
@app.output(Images(key="outputImage"))
def SPImageSeg(context):
    args = context.args
    images = args.inputImage

    for idx, img in enumerate(images):
        splitX, splitY = (
            math.ceil(img.shape[1] / args.x),
            math.ceil(img.shape[0] / args.y),
        )
        i = 0
        for m in range(splitX):
            for n in range(splitY):
                filename = (
                    os.path.splitext(
                        storage.delimiter.join(
Exemple #10
0
# coding=utf-8
from __future__ import absolute_import, print_function

import os
from suanpan.app.arguments import Folder, String, Int, Bool
from suanpan.app import app
from mainscripts import VideoEd
from utils import get_all_files


@app.input(Folder(key="inputData"))
@app.input(Folder(key="referenceFolder"))
@app.param(String(key="fileName", default="media.mp4"))
@app.param(String(key="ext", default="png", help="jpg png"))
@app.param(Int(key="fps", default=25))
@app.param(Int(key="bitrate", default=16))
@app.param(Bool(key="lossless", default=False))
@app.output(Folder(key="outputData"))
def SPVideoFromSequence(context):
    args = context.args
    if args.referenceFolder:
        referenceFile = get_all_files(args.referenceFolder)

    VideoEd.video_from_sequence(
        args.inputData,
        os.path.join(args.outputData, args.fileName),
        referenceFile[0],
        args.ext,
        args.fps,
        args.bitrate,
        args.lossless,
Exemple #11
0
import os
from suanpan.app.arguments import Folder, String, Int, Bool
from suanpan.app import app


@app.input(Folder(key="inputData"))
@app.input(Folder(key="alignedDir"))
@app.input(Folder(key="modelDir"))
@app.param(Bool(key="__edit", default=False))
@app.param(
    String(
        key="modelName",
        default="SAE",
        help="AVATAR, DF, H64, H128, LIAEF128, SAE, DEV_FANSEG",
    ))
@app.param(Int(key="forceGpuIdx", default=-1))
@app.param(Bool(key="cpuOnly", default=False))
@app.output(Folder(key="outputData"))
def SPConvertLab(context):
    args = context.args

    convert_args = {
        "input_dir": args.inputData,
        "output_dir": args.outputData,
        "aligned_dir": args.alignedDir,
        "model_dir": args.modelDir,
        "model_name": args.modelName,
    }
    device_args = {
        "cpu_only": args.cpuOnly,
        "force_gpu_idx": args.forceGpuIdx,
Exemple #12
0
# coding=utf-8
from __future__ import absolute_import, print_function

import os
from suanpan.app.arguments import Folder, Int, String, Bool
from suanpan.app import app
from lib import cli


@app.input(Folder(key="inputData1"))
@app.input(Folder(key="alignments1"))
@app.input(Folder(key="inputData2"))
@app.input(Folder(key="alignments2"))
@app.param(Int(key="batchSize", default=4, help="64 (2, 256)"))
@app.param(
    String(
        key="trainer",
        default="original",
        help=
        "original dfaker dfl-h128 dfl-sae iae lightweight realface unbalanced villain",
    ))
@app.param(Int(key="iterations", default=10000, help="1000000 (0, 5000000)"))
@app.param(Int(key="__gpu", default=0))
@app.param(Bool(key="allowGrowth", default=False))
@app.param(Bool(key="warpToLandmarks", default=False))
@app.param(Bool(key="noFlip", default=False))
@app.param(Bool(key="noAugmentColor", default=False))
@app.output(Folder(key="outputModel"))
def SPTrain(context):
    args = context.args
Exemple #13
0
import shutil
from utils import get_all_files


@app.input(Folder(key="trainingDataSrcDir"))
@app.input(Folder(key="trainingDataDstDir"))
@app.input(Folder(key="pretrainingDataDir"))
@app.input(Folder(key="pretrainedModelDir"))
@app.param(Bool(key="__edit", default=False))
@app.param(
    String(
        key="modelName",
        default="H128",
        help="AVATAR, DF, H64, H128, LIAEF128, SAE, DEV_FANSEG",
    ))
@app.param(Int(key="iterations", default=1100284))
@app.param(Int(key="batchSize", default=4))
@app.param(Int(key="forceGpuIdx", default=-1))
@app.param(Bool(key="cpuOnly", default=False))
@app.output(Folder(key="modelDir"))
def SPTrainLab(context):
    args = context.args
    if args.pretrainedModelDir:
        modelList = get_all_files(args.pretrainedModelDir)
        for i in modelList:
            shutil.copy(i, os.path.join(args.modelDir, os.path.split(i)[1]))
    training_args = {
        "training_data_src_dir": args.trainingDataSrcDir,
        "training_data_dst_dir": args.trainingDataDstDir,
        "pretraining_data_dir": args.pretrainingDataDir,
        "model_path": args.modelDir,
Exemple #14
0
        P.copy(self.model_dir, path)
        return path

    def train(self, X, y, epochs=10):
        pass

    def evaluate(self, X, y):
        pass

    def predict(self, X):
        pass


@app.input(Folder(key="inputData1", alias="data"))
@app.input(Folder(key="inputData2", alias="model_config"))
@app.param(Int(key="param1", alias="num_train_steps", default=1))
@app.output(Model(key="outputModel1", alias="model", type=ODModel))
def SPObjectDetection(context):
    args = context.args
    P.copy(args.data, "./data")
    os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"  # 指定第一块GPU可用
    sess = tf.Session()
    FLAGS = {}
    FLAGS["model_dir"] = "./model"
    FLAGS["pipeline_config_path"] = os.path.join(
        args.model_config, "ssd_mobilenet_v1_coco.config")
    FLAGS["num_train_steps"] = args.num_train_steps
    FLAGS["eval_training_data"] = False
    FLAGS["sample_1_of_n_eval_examples"] = 1
    FLAGS["sample_1_of_n_eval_on_train_examples"] = 5
    FLAGS["hparams_overrides"] = None
Exemple #15
0
# coding=utf-8
from __future__ import absolute_import, print_function

import os
import suanpan
from suanpan.app import app
from suanpan.app.arguments import Folder, Int, Model, Float
from model import TFModel


@app.input(Folder(key="inputData1", alias="trainImages"))
@app.output(Model(key="outputModel1", alias="model", type=TFModel))
@app.output(Folder(key="outputData2", alias="log"))
@app.param(Float(key="param1", alias="lr", default=0.0001))
@app.param(Int(key="param2", alias="bs", default=64))
@app.param(Int(key="param3", alias="max_step", default=1, help="4501"))
@app.param(Int(key="param4", alias="decay_steps", default=233))
@app.param(Float(key="param5", alias="end_learning_rate", default=0.000001))
@app.param(Float(key="param6", alias="power", default=0.5))
@app.param(Float(key="param7", alias="cycle", default=False))
@app.param(Float(key="param8", alias="cap", default=64))
@app.param(Int(key="param9", alias="n_classes", default=7))
@app.param(Int(key="param10", alias="img_w", default=72))
@app.param(Int(key="param11", alias="img_h", default=72))
def SPClassificationTrain(context):
    args = context.args
    prepare_params = {
        "img_w": args.img_w,
        "img_h": args.img_h,
        "batch_size": args.bs,
        "cap": args.cap,
Exemple #16
0
# coding=utf-8
from __future__ import absolute_import, print_function

from suanpan.app.arguments import Folder, String, Int
from suanpan.app import app
from mainscripts import VideoEd
from utils import get_all_files


@app.input(Folder(key="inputData"))
@app.param(String(key="outputExt", default="png", help="jpg png"))
@app.param(Int(key="fps", default=0))
@app.output(Folder(key="outputData"))
def SPExtractVideo(context):
    args = context.args

    inputFile = get_all_files(args.inputData)

    VideoEd.extract_video(inputFile[0], args.outputData, args.outputExt,
                          args.fps)

    return args.outputData


if __name__ == "__main__":
    SPExtractVideo()