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
# coding=utf-8
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))
Exemple #3
0
# coding=utf-8
from __future__ import absolute_import, print_function

import os
import numpy as np
from PIL import Image
from suanpan.app import app
from suanpan.app.arguments import Folder, Json
from suanpan.utils import image as im


@app.input(Folder(key="inputData1"))
@app.input(Json(key="inputData2"))
@app.output(Folder(key="outputData1"))
def SPROI(context):
    args = context.args
    image_folder = args.inputData1
    detection_dict = args.inputData2
    images = os.listdir(image_folder)
    for i, img in enumerate(images):
        image = Image.open(os.path.join(image_folder, img))
        im_height, im_width = image.size
        boxes = detection_dict[i]["detection_boxes"]
        y_min = boxes[0][0] * im_height
        x_min = boxes[0][1] * im_width
        y_max = boxes[0][2] * im_height
        x_max = boxes[0][3] * im_width

        x_2 = int((x_min + x_max) / 2) + 72
        y_1 = int(y_max + 10)
        x_1 = int(x_2 - 72)
Exemple #4
0
# coding=utf-8
from __future__ import absolute_import, print_function

import tensorflow as tf
import suanpan
from suanpan.app import app
from suanpan.app.arguments import Folder, Model, Json
from model import TFModel
from utils.prework import get_predict_file, get_image


@app.input(Folder(key="inputData1", alias="predictImages"))
@app.input(Model(key="inputModel2", alias="model", type=TFModel))
@app.output(Json(key="outputData1", alias="predictions"))
def SPClassificationPredict(context):
    args = context.args
    predict_image = get_predict_file(args.predictImages)
    predictions = []
    with tf.Graph().as_default():
        for image in get_image(predict_image):
            labelnum = args.model.predict(image, args.model.model_dir)
            predictions.append(list(args.model.label_map.keys())[labelnum])

    return predictions


@app.afterCall
def modelHotReload(context):
    args = context.args
    if app.isStream:
        args.model.reload(duration=args.duration)
Exemple #5
0
# coding=utf-8
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)
Exemple #6
0
                # all outputs are float32 numpy arrays, so convert types as appropriate
                output_dict["num_detections"] = int(
                    output_dict["num_detections"][0])
                output_dict["detection_classes"] = output_dict[
                    "detection_classes"][0].astype(np.int64)
                output_dict["detection_boxes"] = output_dict[
                    "detection_boxes"][0]
                output_dict["detection_scores"] = output_dict[
                    "detection_scores"][0]
                if "detection_masks" in output_dict:
                    output_dict["detection_masks"] = output_dict[
                        "detection_masks"][0]
        return output_dict


@app.input(Folder(key="inputData1", alias="predictImages"))
@app.input(Model(key="inputModel2", alias="model", type=ODModel))
@app.output(Json(key="outputData1", alias="predictions"))
@app.output(Folder(key="outputData2", alias="images"))
def SPObjectDetectionPrediction(context):
    args = context.args
    predict_image = get_predict_file(args.predictImages)
    bboxes = []
    i = 0
    for inputImage in get_od_image(predict_image):
        predictedBox, imageBox = args.model.predict(inputImage)
        bboxes.append(predictedBox)
        image.save(
            os.path.join(
                args.images,
                storage.delimiter.join(predict_image[i].split(
Exemple #7
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


@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,
    }
Exemple #8
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 #9
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 #10
0
# coding=utf-8
from __future__ import absolute_import, print_function

import multiprocessing
import os
from suanpan.app.arguments import Folder, String, Bool, Int
from suanpan.app import app
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)
Exemple #11
0
# coding=utf-8
from __future__ import absolute_import, print_function

import os
import sys
import suanpan
from suanpan.app import app
from suanpan.app.arguments import Folder, Float, Json
from utils.utils import reCalcHoleGrid, preMain
from utils import get_all_files


@app.input(Folder(key="inputData1", required=True))
@app.input(Json(key="points"))
@app.param(Float(key="heightReal", default=1.0289))
@app.param(Float(key="widthReal", default=1.0294))
@app.output(Folder(key="outputData1", required=True))
def GridPre(context):

    args = context.args

    print(args.inputData1)
    imgs = get_all_files(args.inputData1)

    points = args.points

    for img in imgs:
        imgpath = img.split("/")
        preMain(
            imgpath=img,
            saved_path=os.path.join(args.outputData1, *imgpath[8:-1]),
Exemple #12
0
# coding=utf-8
from __future__ import absolute_import, print_function

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


@app.input(Folder(key="inputData1"))
@app.input(Folder(key="inputData2"))
@app.input(Folder(key="inputModel"))
@app.param(
    String(
        key="colorAdjustment",
        default="avg-color",
        help=
        "avg-color color-transfer manual-balance match-hist seamless-clone none",
    ))
@app.param(Int(key="__gpu", default=0))
@app.param(
    String(
        key="maskType",
        default="predicted",
        help="components dfl_full extended facehull predicted none",
    ))
@app.param(String(key="scaling", default="none", help="sharpen none"))
@app.output(Folder(key="outputData"))
def SPConvert(context):
    args = context.args
Exemple #13
0
    def save(self, path):
        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
Exemple #14
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,