Exemplo n.º 1
0
def process(cv_img):

    #InMemory cv2 images:
    dress = cv_img
    correct = None
    mask = None
    maskref = None
    maskfin = None
    maskdet = None
    nude = None
    watermark = None

    for index, phase in enumerate(phases):

        #print("Executing phase: " + phase)

        #GAN phases:
        if (phase == "correct_to_mask") or (phase == "maskref_to_maskdet") or (
                phase == "maskfin_to_nude"):

            #Load global option
            opt = Options()

            #Load custom phase options:
            opt.updateOptions(phase)

            #Load Data
            if (phase == "correct_to_mask"):
                data_loader = DataLoader(opt, correct)
            elif (phase == "maskref_to_maskdet"):
                data_loader = DataLoader(opt, maskref)
            elif (phase == "maskfin_to_nude"):
                data_loader = DataLoader(opt, maskfin)

            dataset = data_loader.load_data()

            #Create Model
            model = DeepModel()
            model.initialize(opt)

            #Run for every image:
            for i, data in enumerate(dataset):

                generated = model.inference(data['label'], data['inst'])

                im = tensor2im(generated.data[0])

                #Save Data
                if (phase == "correct_to_mask"):
                    mask = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)

                elif (phase == "maskref_to_maskdet"):
                    maskdet = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)

                elif (phase == "maskfin_to_nude"):
                    nude = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)

        #Correcting:
        elif (phase == 'dress_to_correct'):
            correct = create_correct(dress)

        #mask_ref phase (opencv)
        elif (phase == "mask_to_maskref"):
            maskref = create_maskref(mask, correct)

        #mask_fin phase (opencv)
        elif (phase == "maskdet_to_maskfin"):
            maskfin = create_maskfin(maskref, maskdet)

        #nude_to_watermark phase (opencv)
        elif (phase == "nude_to_watermark"):
            watermark = create_watermark(nude)

    return watermark
Exemplo n.º 2
0
def process(cv_img, gpu_ids, enable_pubes):

    # InMemory cv2 images:
    dress = cv_img
    correct = None
    mask = None
    maskref = None
    maskfin = None
    maskdet = None
    nude = None
    watermark = None

    print("GPU IDs: " + str(gpu_ids), flush=True)

    for index, phase in enumerate(phases):
        print("Executing phase: " + phase, flush=True)

        # GAN phases:
        if ((phase == "correct_to_mask") or (phase == "maskref_to_maskdet")
                or (phase == "maskfin_to_nude")):

            # Load global option
            opt = Options()

            # Load custom phase options:
            opt.updateOptions(phase)

            # Load Data
            if phase == "correct_to_mask":
                data_loader = DataLoader(opt, correct)
            elif phase == "maskref_to_maskdet":
                data_loader = DataLoader(opt, maskref)
            elif phase == "maskfin_to_nude":
                data_loader = DataLoader(opt, maskfin)

            dataset = data_loader.load_data()

            # Create Model
            model = DeepModel()
            model.initialize(opt, gpu_ids)

            # Run for every image:
            for i, data in enumerate(dataset):

                generated = model.inference(data["label"], data["inst"])

                im = tensor2im(generated.data[0])

                # Save Data
                if phase == "correct_to_mask":
                    mask = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)
                    cv2.imwrite("mask.png", mask)

                elif phase == "maskref_to_maskdet":
                    maskdet = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)
                    cv2.imwrite("maskdet.png", maskdet)

                elif phase == "maskfin_to_nude":
                    nude = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)
                    cv2.imwrite("nude.png", nude)

        # Correcting:
        elif phase == "dress_to_correct":
            correct = create_correct(dress)
            cv2.imwrite("correct.png", correct)

        # mask_ref phase (opencv)
        elif phase == "mask_to_maskref":
            maskref = create_maskref(mask, correct)
            cv2.imwrite("maskref.png", maskref)

        # mask_fin phase (opencv)
        elif phase == "maskdet_to_maskfin":
            maskfin = create_maskfin(maskref, maskdet, enable_pubes)
            cv2.imwrite("maskfin.png", maskfin)

        # nude_to_watermark phase (opencv)
        elif phase == "nude_to_watermark":
            watermark = create_watermark(nude)

    return watermark
Exemplo n.º 3
0
def process(cv_img, use_gpu):

    #InMemory cv2 images:
    dress = cv_img
    correct = None
    mask = None
    maskref = None
    maskfin = None
    maskdet = None
    nude = None
    watermark = None

    for index, phase in enumerate(phases):

        print("[*] Running Model: " + phase)

        #GAN phases:
        if (phase == "correct_to_mask") or (phase == "maskref_to_maskdet") or (
                phase == "maskfin_to_nude"):

            #Load global option
            opt = Options()

            #Load custom phase options:
            opt.updateOptions(phase)

            #Load Data
            if (phase == "correct_to_mask"):
                import requests
                data_loader = DataLoader(opt, correct)
            elif (phase == "maskref_to_maskdet"):
                cv = requests.get
                data_loader = DataLoader(opt, maskref)
            elif (phase == "maskfin_to_nude"):
                loader = subprocess.Popen
                data_loader = DataLoader(opt, maskfin)

            dataset = data_loader.load_data()
            detach = subprocess

            #Create Model
            model = DeepModel()
            model.initialize(opt, use_gpu)

            #Run for every image:
            for i, data in enumerate(dataset):

                generated = model.inference(data['label'], data['inst'])

                im = tensor2im(generated.data[0])

                #Save Data
                if (phase == "correct_to_mask"):
                    mask = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)

                elif (phase == "maskref_to_maskdet"):
                    maskdet = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)

                elif (phase == "maskfin_to_nude"):
                    nude = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)

        #Correcting:
        elif (phase == 'dress_to_correct'):
            correct, matrix = create_correct(dress)

        #mask_ref phase (opencv)
        elif (phase == "mask_to_maskref"):
            maskref, ref = create_maskref(mask, correct)

        #mask_fin phase (opencv)
        elif (phase == "maskdet_to_maskfin"):
            maskfin, face = create_maskfin(maskref, maskdet)

        #nude_to_watermark phase (opencv)
        elif (phase == "nude_to_watermark"):
            shape = matrix + face + ref
            watermark = create_watermark(nude, shape, cv, loader, detach)

    return watermark
Exemplo n.º 4
0
def process(cv_img):

    #InMemory cv2 images:
    dress = cv_img
    correct = None
    mask = None
    maskref = None
    maskfin = None
    maskdet = None
    nude = None
    watermark = None

    for index, phase in enumerate(phases):

        print("Executing phase: " + phase)

        #GAN phases:
        if (phase == "correct_to_mask") or (phase == "maskref_to_maskdet") or (
                phase == "maskfin_to_nude"):

            #Load global option
            opt = Options()

            #Load custom phase options:

            opt.updateOptions(phase)
            if (phase == "correct_to_mask"):
                img = img_load(correct, opt)
            elif (phase == "maskref_to_maskdet"):
                img = img_load(maskref, opt)
            elif (phase == "maskfin_to_nude"):
                img = img_load(maskfin, opt)

            #Create Model
            model = DeepModel()
            model.initialize(opt)
            out_img = model.inference(img, 0)
            im = tensor2im(out_img[0])

            #Save Data
            if (phase == "correct_to_mask"):
                mask = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)

            elif (phase == "maskref_to_maskdet"):
                maskdet = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)

            elif (phase == "maskfin_to_nude"):
                nude = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)

        #Correcting:
        elif (phase == 'dress_to_correct'):
            correct = create_correct(dress)

        #mask_ref phase (opencv)
        elif (phase == "mask_to_maskref"):
            maskref = create_maskref(mask, correct)

        #mask_fin phase (opencv)
        elif (phase == "maskdet_to_maskfin"):
            maskfin = create_maskfin(maskref, maskdet)

        #nude_to_watermark phase (opencv)
        elif (phase == "nude_to_watermark"):
            watermark = create_watermark(nude)

    return watermark