File size: 2,575 Bytes
bc0db10
1ad0483
8a26694
a0287a0
1ad0483
8a26694
1ad0483
2900131
1c46df5
bc0db10
 
 
1c46df5
2900131
1c46df5
8a26694
 
2900131
 
1c46df5
 
8a26694
2900131
bc0db10
2900131
 
8a26694
2900131
bc0db10
2900131
8a26694
2900131
baf4bca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f4e9401
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import spaces
import gradio as gr
import numpy as np
import torch

from chrislib.general import uninvert, invert, view, view_scale

from intrinsic.pipeline import load_models, run_pipeline

DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

intrinsic_models = load_models('v2', device=DEVICE)

def generate_pipeline(models):

    def pipeline_func(image, **kwargs):
        return run_pipeline(models, image, **kwargs)
    
    return pipeline_func


pipeline_func = generate_pipeline(intrinsic_models)

@spaces.GPU
def process_image(image):
    print(image.shape)
    image = image.astype(np.single) / 255.

    result = pipeline_func(image, device=DEVICE)
    
    return [view(result['hr_alb']), 1 - invert(result['dif_shd']), view_scale(result['pos_res'])]

with gr.Blocks(
    css="""
        #download {
            height: 118px;
        }
        .slider .inner {
            width: 5px;
            background: #FFF;
        }
        .viewport {
            aspect-ratio: 4/3;
        }
        .tabs button.selected {
            font-size: 20px !important;
            color: crimson !important;
        }
        h1 {
            text-align: center;
            display: block;
        }
        h2 {
            text-align: center;
            display: block;
        }
        h3 {
            text-align: center;
            display: block;
        }
        .md_feedback li {
            margin-bottom: 0px !important;
        }
        """,
) as demo:
    gr.Markdown(
            """
            # Colorful Diffuse Intrinsic Image Decomposition in the Wild
            <p align="center">
            <a title="Website" href="https://yaksoy.github.io/ColorfulShading/" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
                <img src="https://www.obukhov.ai/img/badges/badge-website.svg">
            </a>
            <a title="Github" href="https://github.com/compphoto/Intrinsic" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
                <img src="https://img.shields.io/github/stars/compphoto/Intrinsic?label=GitHub%20%E2%98%85&logo=github&color=C8C" alt="badge-github-stars">
            </a>
        """
    )
    with gr.Row():
        input_img = gr.Image(label="Input Image")

    with gr.Row():
        alb_img = gr.Image(label="Albedo")
        shd_img = gr.Image(label="Diffuse Shading")
        dif_img = gr.Image(label="Diffuse Image")

    input_img.change(process_image, inputs=input_img, outputs=[alb_img, shd_img, dif_img])

demo.launch(show_error=True)