1
+ {
2
+ "nbformat" : 4 ,
3
+ "nbformat_minor" : 0 ,
4
+ "metadata" : {
5
+ "colab" : {
6
+ "provenance" : [],
7
+ "gpuType" : " T4"
8
+ },
9
+ "kernelspec" : {
10
+ "name" : " python3" ,
11
+ "display_name" : " Python 3"
12
+ },
13
+ "language_info" : {
14
+ "name" : " python"
15
+ },
16
+ "accelerator" : " GPU"
17
+ },
18
+ "cells" : [
19
+ {
20
+ "cell_type" : " code" ,
21
+ "execution_count" : null ,
22
+ "metadata" : {
23
+ "id" : " _cPkUxN-ikld"
24
+ },
25
+ "outputs" : [],
26
+ "source" : [
27
+ " # install the intrinsic decomposition repo from github\n " ,
28
+ " !pip install https://github.com/compphoto/Intrinsic/archive/main.zip"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type" : " code" ,
33
+ "source" : [
34
+ " import torch\n " ,
35
+ " \n " ,
36
+ " # import some helper functions from chrislib (will be installed by the intrinsic repo)\n " ,
37
+ " from chrislib.general import show, view, uninvert\n " ,
38
+ " from chrislib.data_util import load_image\n " ,
39
+ " \n " ,
40
+ " # import model loading and running the pipeline\n " ,
41
+ " from intrinsic.pipeline import run_pipeline\n " ,
42
+ " from intrinsic.model_util import load_models"
43
+ ],
44
+ "metadata" : {
45
+ "id" : " J0gn82ZSjomn"
46
+ },
47
+ "execution_count" : null ,
48
+ "outputs" : []
49
+ },
50
+ {
51
+ "cell_type" : " code" ,
52
+ "source" : [
53
+ " # download the pretrained weights and return the model (may take a bit to download weights)\n " ,
54
+ " intrinsic_model = load_models('paper_weights')"
55
+ ],
56
+ "metadata" : {
57
+ "id" : " Ap3HubpwC_KG"
58
+ },
59
+ "execution_count" : null ,
60
+ "outputs" : []
61
+ },
62
+ {
63
+ "cell_type" : " code" ,
64
+ "source" : [
65
+ " # load an example image from the github repo\n " ,
66
+ " torch.hub.download_url_to_file('https://raw.githubusercontent.com/compphoto/Intrinsic/main/figures/avocado.png', 'avo.png')"
67
+ ],
68
+ "metadata" : {
69
+ "id" : " m_NYfDx0AhTw"
70
+ },
71
+ "execution_count" : null ,
72
+ "outputs" : []
73
+ },
74
+ {
75
+ "cell_type" : " code" ,
76
+ "source" : [
77
+ " # load the image to run through the pipeline\n " ,
78
+ " img = load_image('/content/avo.png')"
79
+ ],
80
+ "metadata" : {
81
+ "id" : " ALb4Pjfvj-MU"
82
+ },
83
+ "execution_count" : null ,
84
+ "outputs" : []
85
+ },
86
+ {
87
+ "cell_type" : " code" ,
88
+ "source" : [
89
+ " # run the image through the pipeline (use R0 resizing dicussed in the paper)\n " ,
90
+ " result = run_pipeline(\n " ,
91
+ " intrinsic_model,\n " ,
92
+ " img,\n " ,
93
+ " resize_conf=0.0,\n " ,
94
+ " maintain_size=True,\n " ,
95
+ " linear=False,\n " ,
96
+ " device='cuda'\n " ,
97
+ " )"
98
+ ],
99
+ "metadata" : {
100
+ "id" : " QW0TiFypkOj-"
101
+ },
102
+ "execution_count" : null ,
103
+ "outputs" : []
104
+ },
105
+ {
106
+ "cell_type" : " code" ,
107
+ "source" : [
108
+ " # convert the inverse shading to regular shading for visualization\n " ,
109
+ " shd = uninvert(result['inv_shading'])\n " ,
110
+ " alb = result['albedo']"
111
+ ],
112
+ "metadata" : {
113
+ "id" : " XpYY2MNjkp2f"
114
+ },
115
+ "execution_count" : null ,
116
+ "outputs" : []
117
+ },
118
+ {
119
+ "cell_type" : " code" ,
120
+ "source" : [
121
+ " # show the result (gamma corrects the linear intrinsic components and scales to [0-1])\n " ,
122
+ " show([img, view(shd), view(alb)], size=(20, 7))"
123
+ ],
124
+ "metadata" : {
125
+ "id" : " 8KKbyoVLki9s"
126
+ },
127
+ "execution_count" : null ,
128
+ "outputs" : []
129
+ }
130
+ ]
131
+ }
0 commit comments