vivekvar commited on
Commit
624cd8c
·
verified ·
1 Parent(s): 490c0c6

Upload 13 files

Browse files
.gitattributes CHANGED
@@ -1,35 +1,4 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.caffemodel filter=lfs diff=lfs merge=lfs -text
2
+ Input_images/pexels-pixabay-141651.jpg filter=lfs diff=lfs merge=lfs -text
3
+ Result_images/colored_c7.jpg filter=lfs diff=lfs merge=lfs -text
4
+ Result_images/colored_c8.jpg filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Input_images/che-guevara-wallpapers-hd-best-hd-photos-1080p-6xcp2u-741x988.jpg ADDED
Input_images/pexels-pixabay-141651.jpg ADDED

Git LFS Details

  • SHA256: 3537f82ccd8c0467878e80b38ba0b0d45bfbb4b41caaef7232a7f3aace51898b
  • Pointer size: 132 Bytes
  • Size of remote file: 7.89 MB
Input_images/pexels-pixabay-36755.jpg ADDED
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2020] [Dhananjayan R]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md CHANGED
@@ -1,13 +1,107 @@
1
- ---
2
- title: Colozier
3
- emoji: 🔥
4
- colorFrom: green
5
- colorTo: red
6
- sdk: streamlit
7
- sdk_version: 1.34.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Colorizer
2
+ Black and white image colorization with OpenCV.
3
+ ## Table of Content
4
+ * [Demo](#demo)
5
+ * [Overview](#overview)
6
+ * [Motivation](#motivation)
7
+ * [Technical Aspect](#technical-aspect)
8
+ * [Installation And Run](#installation-and-run)
9
+ * [Directory Tree](#directory-tree)
10
+ * [To Do](#to-do)
11
+ * [Bug / Feature Request](#bug---feature-request)
12
+ * [Technologies Used](#technologies-used)
13
+ * [Team](#team)
14
+ * [License](#license)
15
+ * [Credits](#credits)
16
+ ## Demo
17
+ ![Alt Text](https://j.gifs.com/2xVL2P.gif)
18
+
19
+ ## Overview
20
+ Image colorization is the process of taking an input grayscale (black and white) image and then producing an output colorized image that represents the semantic colors and tones of the input (for example, an ocean on a clear sunny day must be plausibly “blue” — it can’t be colored “hot pink” by the model).
21
+
22
+ ## Motivation
23
+
24
+ When I learned linear algebra and came to know about how the machine inteprets pictures as tensors and concept of image segmentation. I remember there were some movies which was restored and picutured in theatre. I just came across Research papers of University of california in image colorization. And most iimportantly when I colorized photos of my Grandmother with gorgeous saree, that smile in my mother's face worth it.
25
+
26
+ Here is a photo of Che guevara from 60's colorized:
27
+
28
+ <img target="_blank" src="https://github.com/dhananjayan-r/Colorizer/blob/master/Input_images/che-guevara-wallpapers-hd-best-hd-photos-1080p-6xcp2u-741x988.jpg" width=300><img target="_blank" src="https://github.com/dhananjayan-r/Colorizer/blob/master/Result_images/colored_c1.jpg" width=300>
29
+
30
+ ## Technical Aspect
31
+ - The technique we’ll be covering here today is from Zhang et al.’s 2016 ECCV paper, [Colorful Image Colorization](http://richzhang.github.io/colorization/). Developed at the University of California, Berkeley by Richard Zhang, Phillip Isola, and Alexei A. Efros.
32
+
33
+ - Previous approaches to black and white image colorization relied on manual human annotation and often produced desaturated results that were not “believable” as true colorizations.
34
+
35
+ - Zhang et al. decided to attack the problem of image colorization by using Convolutional Neural Networks to “hallucinate” what an input grayscale image would look like when colorized.
36
+
37
+ - To train the network Zhang et al. started with the [ImageNet dataset](http://image-net.org/) and converted all images from the RGB color space to the Lab color space.
38
+
39
+ - Similar to the RGB color space, the Lab color space has three channels. But unlike the RGB color space, Lab encodes color information differently:
40
+ - The **L channel** encodes lightness intensity only
41
+ - The **a channel** encodes green-red.
42
+ - And the **b channel** encodes blue-yellow.
43
+
44
+ - As explained in the original paper, the authors, embraced the underlying uncertainty of the problem by posing it as a classification task using class-rebalancing at training time to increase the diversity of colors in the result. The Artificial Intelligent (AI) approach is implemented as a feed-forward pass in a CNN (“Convolutional Neural Network”) at test time and is trained on over a million color images.
45
+
46
+ - The color photos were decomposed using Lab model and “L channel” is used as an input feature and “a and b channels” as classification labels as shown in below diagram.
47
+
48
+ <img target="_blank" src="https://user-images.githubusercontent.com/71431013/99061015-eb844a80-25c6-11eb-8850-bcc9f74d91e6.png" width=500>
49
+
50
+ - The trained model (that is available publically and in models folder of this repo or [download it by clicking here]( http://eecs.berkeley.edu/~rich.zhang/projects/2016_colorization/files/demo_v2/colorization_release_v2.caffemodel)), we can use it to colorize a new B&W photo, where this photo will be the input of the model or the component “L”. The output of the model will be the other components “a” and “b”, that once added to the original “L”, will return a full colorized image.
51
+
52
+ ## The entire (simplified) process can be summarized as:
53
+ - Convert all training images from the RGB color space to the Lab color space.
54
+ - Use the L channel as the input to the network and train the network to predict the ab channels.
55
+ - Combine the input L channel with the predicted ab channels.
56
+ - Convert the Lab image back to RGB.
57
+
58
+ <img target="_blank" src="https://user-images.githubusercontent.com/71431013/99061033-f048fe80-25c6-11eb-8bc5-d6312c7021b6.png" width=500>
59
+
60
+ ## Installation And Run
61
+ 1.The Code is written in Python 3.7. If you don't have Python installed you can find it [here](https://www.python.org/downloads/). If you are using a lower version of Python you can upgrade using the pip package, ensuring you have the latest version of pip. To install the required packages and libraries, run this command in the project directory after [cloning](https://www.howtogeek.com/451360/how-to-clone-a-github-repository/) the repository:
62
+ ```bash
63
+ pip install -r requirements.txt
64
+ ```
65
+ 2. [Run the file with](https://docs.streamlit.io/en/stable/):
66
+ ```bash
67
+ $ streamlit run app.py
68
+ ```
69
+
70
+ ## Directory Tree
71
+ ```
72
+ | app.py
73
+ +---Input_images
74
+ | che-guevara-.jpg
75
+ | pexels-pixabay-141651.jpg
76
+ | pexels-pixabay-36755.jpg
77
+ +---models
78
+ | colorization_release_v2.caffemodel
79
+ | models_colorization_deploy_v2.prototxt
80
+ | pts_in_hull.npy
81
+ \---Result_images
82
+ colored_c1.jpg
83
+ colored_c7.jpg
84
+ colored_c8.jpg
85
+ ```
86
+ ## To Do
87
+ - To Convert the application to colorize black and white videos.
88
+
89
+ ## Bug / Feature Request
90
+ If you find a bug , kindly open an issue [here](https://github.com/dhananjayan-r/Colorizer/issues) by including your search query and the expected result.
91
+
92
+ If you'd like to request a new function, feel free to do so by opening an issue [here](https://github.com/dhananjayan-r/Colorizer/issues). Please include sample queries and their corresponding results.
93
+
94
+ ## Technologies Used
95
+ ![](https://forthebadge.com/images/badges/made-with-python.svg)
96
+
97
+ [<img target="_blank" src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/OpenCV_Logo_with_text_svg_version.svg/730px-OpenCV_Logo_with_text_svg_version.svg.png" width=200>](https://opencv.org/)[<img target="_blank" src="https://miro.medium.com/max/4000/0*cSCGhssjeajRD3qs.png" width=200>](https://www.streamlit.io/)
98
+
99
+ ## Team
100
+ [<img target="_blank" src="" width=200>](www.linkedin.com/in/vivek-vari/)|
101
+ -|
102
+ [vivek](www.linkedin.com/in/vivek-vari/) |)
103
+
104
+
105
+ ## Credits
106
+ - [“ Black and white image colorization with OpenCV and Deep Learning” by Dr. Adrian Rosebrok "](https://www.pyimagesearch.com/2019/02/25/black-and-white-image-colorization-with-opencv-and-deep-learning/) - This project wouldn't have been possible without these references.
107
+ - [The official publication of Zhang et al.](http://richzhang.github.io/colorization/)
Result_images/colored_c1.jpg ADDED
Result_images/colored_c7.jpg ADDED

Git LFS Details

  • SHA256: 2254ec2af30f940399a3704c6ba1f25aef907e0fc55d15eaf80b55ce0067b91c
  • Pointer size: 133 Bytes
  • Size of remote file: 13.6 MB
Result_images/colored_c8.jpg ADDED

Git LFS Details

  • SHA256: 9c4fdc1e4d69522114880619ee255a0ffbefba5c426576615446762dda8cb4cf
  • Pointer size: 132 Bytes
  • Size of remote file: 1.52 MB
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[6]:
5
+
6
+
7
+
8
+ # import the necessary packages
9
+ import numpy as np
10
+ import cv2
11
+ import streamlit as st
12
+ from PIL import Image
13
+
14
+
15
+
16
+ def colorizer(img):
17
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
18
+ img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
19
+ # load our serialized black and white colorizer model and cluster
20
+ # center points from disk
21
+ #Note: Please take in account the directories of your local system.
22
+ prototxt = r"C:\Users\dhananjayan\projects\Colorizer\models\models_colorization_deploy_v2.prototxt"
23
+ model = r"C:\Users\dhananjayan\projects\Colorizer\models\colorization_release_v2.caffemodel"
24
+ points = r"C:\Users\dhananjayan\projects\Colorizer\models\pts_in_hull.npy"
25
+ net = cv2.dnn.readNetFromCaffe(prototxt, model)
26
+ pts = np.load(points)
27
+ # add the cluster centers as 1x1 convolutions to the model
28
+ class8 = net.getLayerId("class8_ab")
29
+ conv8 = net.getLayerId("conv8_313_rh")
30
+ pts = pts.transpose().reshape(2, 313, 1, 1)
31
+ net.getLayer(class8).blobs = [pts.astype("float32")]
32
+ net.getLayer(conv8).blobs = [np.full([1, 313], 2.606, dtype="float32")]
33
+ # scale the pixel intensities to the range [0, 1], and then convert the image from the BGR to Lab color space
34
+ scaled = img.astype("float32") / 255.0
35
+ lab = cv2.cvtColor(scaled, cv2.COLOR_RGB2LAB)
36
+ # resize the Lab image to 224x224 (the dimensions the colorization
37
+ #network accepts), split channels, extract the 'L' channel, and then perform mean centering
38
+ resized = cv2.resize(lab, (224, 224))
39
+ L = cv2.split(resized)[0]
40
+ L -= 50
41
+ # pass the L channel through the network which will *predict* the 'a' and 'b' channel values
42
+ net.setInput(cv2.dnn.blobFromImage(L))
43
+ ab = net.forward()[0, :, :, :].transpose((1, 2, 0))
44
+ # resize the predicted 'ab' volume to the same dimensions as our input image
45
+ ab = cv2.resize(ab, (img.shape[1], img.shape[0]))
46
+ # grab the 'L' channel from the *original* input image (not the
47
+ # resized one) and concatenate the original 'L' channel with the predicted 'ab' channels
48
+ L = cv2.split(lab)[0]
49
+ colorized = np.concatenate((L[:, :, np.newaxis], ab), axis=2)
50
+ # convert the output image from the Lab color space to RGB, then clip any values that fall outside the range [0, 1]
51
+ colorized = cv2.cvtColor(colorized, cv2.COLOR_LAB2RGB)
52
+ colorized = np.clip(colorized, 0, 1)
53
+ # the current colorized image is represented as a floating point
54
+ # data type in the range [0, 1] -- let's convert to an unsigned 8-bit integer representation in the range [0, 255]
55
+ colorized = (255 * colorized).astype("uint8")
56
+ # Return the colorized images
57
+ return colorized
58
+
59
+ ##########################################################################################################
60
+
61
+ st.write("""
62
+ # Colorize your Black and white image
63
+ """
64
+ )
65
+
66
+ st.write("This is an app to turn Colorize your B&W images.")
67
+ st.write("Created on Thursday, 12 November 2020 (IST) \n @author: Dhananjayan")
68
+
69
+ file = st.sidebar.file_uploader("Please upload an image file", type=["jpg", "png"])
70
+
71
+ if file is None:
72
+ st.text("You haven't uploaded an image file")
73
+ else:
74
+ image = Image.open(file)
75
+ img = np.array(image)
76
+
77
+ st.text("Your original image")
78
+ st.image(image, use_column_width=True)
79
+
80
+ st.text("Your colorized image")
81
+ color = colorizer(img)
82
+
83
+ st.image(color, use_column_width=True)
84
+
85
+ print("done!")
86
+
87
+
88
+ # In[ ]:
89
+
90
+
91
+
92
+
models/colorization_release_v2.caffemodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a0b0ec746f8f3100a7f14f6e18176032300123d9bebe79a7081fa9f1b7a9cbe
3
+ size 134
models/models_colorization_deploy_v2.prototxt ADDED
@@ -0,0 +1,589 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "LtoAB"
2
+
3
+ layer {
4
+ name: "data_l"
5
+ type: "Input"
6
+ top: "data_l"
7
+ input_param {
8
+ shape { dim: 1 dim: 1 dim: 224 dim: 224 }
9
+ }
10
+ }
11
+
12
+ # *****************
13
+ # ***** conv1 *****
14
+ # *****************
15
+ layer {
16
+ name: "bw_conv1_1"
17
+ type: "Convolution"
18
+ bottom: "data_l"
19
+ top: "conv1_1"
20
+ # param {lr_mult: 0 decay_mult: 0}
21
+ # param {lr_mult: 0 decay_mult: 0}
22
+ convolution_param {
23
+ num_output: 64
24
+ pad: 1
25
+ kernel_size: 3
26
+ }
27
+ }
28
+ layer {
29
+ name: "relu1_1"
30
+ type: "ReLU"
31
+ bottom: "conv1_1"
32
+ top: "conv1_1"
33
+ }
34
+ layer {
35
+ name: "conv1_2"
36
+ type: "Convolution"
37
+ bottom: "conv1_1"
38
+ top: "conv1_2"
39
+ # param {lr_mult: 0 decay_mult: 0}
40
+ # param {lr_mult: 0 decay_mult: 0}
41
+ convolution_param {
42
+ num_output: 64
43
+ pad: 1
44
+ kernel_size: 3
45
+ stride: 2
46
+ }
47
+ }
48
+ layer {
49
+ name: "relu1_2"
50
+ type: "ReLU"
51
+ bottom: "conv1_2"
52
+ top: "conv1_2"
53
+ }
54
+ layer {
55
+ name: "conv1_2norm"
56
+ type: "BatchNorm"
57
+ bottom: "conv1_2"
58
+ top: "conv1_2norm"
59
+ batch_norm_param{ }
60
+ param {lr_mult: 0 decay_mult: 0}
61
+ param {lr_mult: 0 decay_mult: 0}
62
+ param {lr_mult: 0 decay_mult: 0}
63
+ }
64
+ # *****************
65
+ # ***** conv2 *****
66
+ # *****************
67
+ layer {
68
+ name: "conv2_1"
69
+ type: "Convolution"
70
+ # bottom: "conv1_2"
71
+ bottom: "conv1_2norm"
72
+ # bottom: "pool1"
73
+ top: "conv2_1"
74
+ # param {lr_mult: 0 decay_mult: 0}
75
+ # param {lr_mult: 0 decay_mult: 0}
76
+ convolution_param {
77
+ num_output: 128
78
+ pad: 1
79
+ kernel_size: 3
80
+ }
81
+ }
82
+ layer {
83
+ name: "relu2_1"
84
+ type: "ReLU"
85
+ bottom: "conv2_1"
86
+ top: "conv2_1"
87
+ }
88
+ layer {
89
+ name: "conv2_2"
90
+ type: "Convolution"
91
+ bottom: "conv2_1"
92
+ top: "conv2_2"
93
+ # param {lr_mult: 0 decay_mult: 0}
94
+ # param {lr_mult: 0 decay_mult: 0}
95
+ convolution_param {
96
+ num_output: 128
97
+ pad: 1
98
+ kernel_size: 3
99
+ stride: 2
100
+ }
101
+ }
102
+ layer {
103
+ name: "relu2_2"
104
+ type: "ReLU"
105
+ bottom: "conv2_2"
106
+ top: "conv2_2"
107
+ }
108
+ layer {
109
+ name: "conv2_2norm"
110
+ type: "BatchNorm"
111
+ bottom: "conv2_2"
112
+ top: "conv2_2norm"
113
+ batch_norm_param{ }
114
+ param {lr_mult: 0 decay_mult: 0}
115
+ param {lr_mult: 0 decay_mult: 0}
116
+ param {lr_mult: 0 decay_mult: 0}
117
+ }
118
+ # *****************
119
+ # ***** conv3 *****
120
+ # *****************
121
+ layer {
122
+ name: "conv3_1"
123
+ type: "Convolution"
124
+ # bottom: "conv2_2"
125
+ bottom: "conv2_2norm"
126
+ # bottom: "pool2"
127
+ top: "conv3_1"
128
+ # param {lr_mult: 0 decay_mult: 0}
129
+ # param {lr_mult: 0 decay_mult: 0}
130
+ convolution_param {
131
+ num_output: 256
132
+ pad: 1
133
+ kernel_size: 3
134
+ }
135
+ }
136
+ layer {
137
+ name: "relu3_1"
138
+ type: "ReLU"
139
+ bottom: "conv3_1"
140
+ top: "conv3_1"
141
+ }
142
+ layer {
143
+ name: "conv3_2"
144
+ type: "Convolution"
145
+ bottom: "conv3_1"
146
+ top: "conv3_2"
147
+ # param {lr_mult: 0 decay_mult: 0}
148
+ # param {lr_mult: 0 decay_mult: 0}
149
+ convolution_param {
150
+ num_output: 256
151
+ pad: 1
152
+ kernel_size: 3
153
+ }
154
+ }
155
+ layer {
156
+ name: "relu3_2"
157
+ type: "ReLU"
158
+ bottom: "conv3_2"
159
+ top: "conv3_2"
160
+ }
161
+ layer {
162
+ name: "conv3_3"
163
+ type: "Convolution"
164
+ bottom: "conv3_2"
165
+ top: "conv3_3"
166
+ # param {lr_mult: 0 decay_mult: 0}
167
+ # param {lr_mult: 0 decay_mult: 0}
168
+ convolution_param {
169
+ num_output: 256
170
+ pad: 1
171
+ kernel_size: 3
172
+ stride: 2
173
+ }
174
+ }
175
+ layer {
176
+ name: "relu3_3"
177
+ type: "ReLU"
178
+ bottom: "conv3_3"
179
+ top: "conv3_3"
180
+ }
181
+ layer {
182
+ name: "conv3_3norm"
183
+ type: "BatchNorm"
184
+ bottom: "conv3_3"
185
+ top: "conv3_3norm"
186
+ batch_norm_param{ }
187
+ param {lr_mult: 0 decay_mult: 0}
188
+ param {lr_mult: 0 decay_mult: 0}
189
+ param {lr_mult: 0 decay_mult: 0}
190
+ }
191
+ # *****************
192
+ # ***** conv4 *****
193
+ # *****************
194
+ layer {
195
+ name: "conv4_1"
196
+ type: "Convolution"
197
+ # bottom: "conv3_3"
198
+ bottom: "conv3_3norm"
199
+ # bottom: "pool3"
200
+ top: "conv4_1"
201
+ # param {lr_mult: 0 decay_mult: 0}
202
+ # param {lr_mult: 0 decay_mult: 0}
203
+ convolution_param {
204
+ num_output: 512
205
+ kernel_size: 3
206
+ stride: 1
207
+ pad: 1
208
+ dilation: 1
209
+ }
210
+ }
211
+ layer {
212
+ name: "relu4_1"
213
+ type: "ReLU"
214
+ bottom: "conv4_1"
215
+ top: "conv4_1"
216
+ }
217
+ layer {
218
+ name: "conv4_2"
219
+ type: "Convolution"
220
+ bottom: "conv4_1"
221
+ top: "conv4_2"
222
+ # param {lr_mult: 0 decay_mult: 0}
223
+ # param {lr_mult: 0 decay_mult: 0}
224
+ convolution_param {
225
+ num_output: 512
226
+ kernel_size: 3
227
+ stride: 1
228
+ pad: 1
229
+ dilation: 1
230
+ }
231
+ }
232
+ layer {
233
+ name: "relu4_2"
234
+ type: "ReLU"
235
+ bottom: "conv4_2"
236
+ top: "conv4_2"
237
+ }
238
+ layer {
239
+ name: "conv4_3"
240
+ type: "Convolution"
241
+ bottom: "conv4_2"
242
+ top: "conv4_3"
243
+ # param {lr_mult: 0 decay_mult: 0}
244
+ # param {lr_mult: 0 decay_mult: 0}
245
+ convolution_param {
246
+ num_output: 512
247
+ kernel_size: 3
248
+ stride: 1
249
+ pad: 1
250
+ dilation: 1
251
+ }
252
+ }
253
+ layer {
254
+ name: "relu4_3"
255
+ type: "ReLU"
256
+ bottom: "conv4_3"
257
+ top: "conv4_3"
258
+ }
259
+ layer {
260
+ name: "conv4_3norm"
261
+ type: "BatchNorm"
262
+ bottom: "conv4_3"
263
+ top: "conv4_3norm"
264
+ batch_norm_param{ }
265
+ param {lr_mult: 0 decay_mult: 0}
266
+ param {lr_mult: 0 decay_mult: 0}
267
+ param {lr_mult: 0 decay_mult: 0}
268
+ }
269
+ # *****************
270
+ # ***** conv5 *****
271
+ # *****************
272
+ layer {
273
+ name: "conv5_1"
274
+ type: "Convolution"
275
+ # bottom: "conv4_3"
276
+ bottom: "conv4_3norm"
277
+ # bottom: "pool4"
278
+ top: "conv5_1"
279
+ # param {lr_mult: 0 decay_mult: 0}
280
+ # param {lr_mult: 0 decay_mult: 0}
281
+ convolution_param {
282
+ num_output: 512
283
+ kernel_size: 3
284
+ stride: 1
285
+ pad: 2
286
+ dilation: 2
287
+ }
288
+ }
289
+ layer {
290
+ name: "relu5_1"
291
+ type: "ReLU"
292
+ bottom: "conv5_1"
293
+ top: "conv5_1"
294
+ }
295
+ layer {
296
+ name: "conv5_2"
297
+ type: "Convolution"
298
+ bottom: "conv5_1"
299
+ top: "conv5_2"
300
+ # param {lr_mult: 0 decay_mult: 0}
301
+ # param {lr_mult: 0 decay_mult: 0}
302
+ convolution_param {
303
+ num_output: 512
304
+ kernel_size: 3
305
+ stride: 1
306
+ pad: 2
307
+ dilation: 2
308
+ }
309
+ }
310
+ layer {
311
+ name: "relu5_2"
312
+ type: "ReLU"
313
+ bottom: "conv5_2"
314
+ top: "conv5_2"
315
+ }
316
+ layer {
317
+ name: "conv5_3"
318
+ type: "Convolution"
319
+ bottom: "conv5_2"
320
+ top: "conv5_3"
321
+ # param {lr_mult: 0 decay_mult: 0}
322
+ # param {lr_mult: 0 decay_mult: 0}
323
+ convolution_param {
324
+ num_output: 512
325
+ kernel_size: 3
326
+ stride: 1
327
+ pad: 2
328
+ dilation: 2
329
+ }
330
+ }
331
+ layer {
332
+ name: "relu5_3"
333
+ type: "ReLU"
334
+ bottom: "conv5_3"
335
+ top: "conv5_3"
336
+ }
337
+ layer {
338
+ name: "conv5_3norm"
339
+ type: "BatchNorm"
340
+ bottom: "conv5_3"
341
+ top: "conv5_3norm"
342
+ batch_norm_param{ }
343
+ param {lr_mult: 0 decay_mult: 0}
344
+ param {lr_mult: 0 decay_mult: 0}
345
+ param {lr_mult: 0 decay_mult: 0}
346
+ }
347
+ # *****************
348
+ # ***** conv6 *****
349
+ # *****************
350
+ layer {
351
+ name: "conv6_1"
352
+ type: "Convolution"
353
+ bottom: "conv5_3norm"
354
+ top: "conv6_1"
355
+ convolution_param {
356
+ num_output: 512
357
+ kernel_size: 3
358
+ pad: 2
359
+ dilation: 2
360
+ }
361
+ }
362
+ layer {
363
+ name: "relu6_1"
364
+ type: "ReLU"
365
+ bottom: "conv6_1"
366
+ top: "conv6_1"
367
+ }
368
+ layer {
369
+ name: "conv6_2"
370
+ type: "Convolution"
371
+ bottom: "conv6_1"
372
+ top: "conv6_2"
373
+ convolution_param {
374
+ num_output: 512
375
+ kernel_size: 3
376
+ pad: 2
377
+ dilation: 2
378
+ }
379
+ }
380
+ layer {
381
+ name: "relu6_2"
382
+ type: "ReLU"
383
+ bottom: "conv6_2"
384
+ top: "conv6_2"
385
+ }
386
+ layer {
387
+ name: "conv6_3"
388
+ type: "Convolution"
389
+ bottom: "conv6_2"
390
+ top: "conv6_3"
391
+ convolution_param {
392
+ num_output: 512
393
+ kernel_size: 3
394
+ pad: 2
395
+ dilation: 2
396
+ }
397
+ }
398
+ layer {
399
+ name: "relu6_3"
400
+ type: "ReLU"
401
+ bottom: "conv6_3"
402
+ top: "conv6_3"
403
+ }
404
+ layer {
405
+ name: "conv6_3norm"
406
+ type: "BatchNorm"
407
+ bottom: "conv6_3"
408
+ top: "conv6_3norm"
409
+ batch_norm_param{ }
410
+ param {lr_mult: 0 decay_mult: 0}
411
+ param {lr_mult: 0 decay_mult: 0}
412
+ param {lr_mult: 0 decay_mult: 0}
413
+ }
414
+ # *****************
415
+ # ***** conv7 *****
416
+ # *****************
417
+ layer {
418
+ name: "conv7_1"
419
+ type: "Convolution"
420
+ bottom: "conv6_3norm"
421
+ top: "conv7_1"
422
+ convolution_param {
423
+ num_output: 512
424
+ kernel_size: 3
425
+ pad: 1
426
+ dilation: 1
427
+ }
428
+ }
429
+ layer {
430
+ name: "relu7_1"
431
+ type: "ReLU"
432
+ bottom: "conv7_1"
433
+ top: "conv7_1"
434
+ }
435
+ layer {
436
+ name: "conv7_2"
437
+ type: "Convolution"
438
+ bottom: "conv7_1"
439
+ top: "conv7_2"
440
+ convolution_param {
441
+ num_output: 512
442
+ kernel_size: 3
443
+ pad: 1
444
+ dilation: 1
445
+ }
446
+ }
447
+ layer {
448
+ name: "relu7_2"
449
+ type: "ReLU"
450
+ bottom: "conv7_2"
451
+ top: "conv7_2"
452
+ }
453
+ layer {
454
+ name: "conv7_3"
455
+ type: "Convolution"
456
+ bottom: "conv7_2"
457
+ top: "conv7_3"
458
+ convolution_param {
459
+ num_output: 512
460
+ kernel_size: 3
461
+ pad: 1
462
+ dilation: 1
463
+ }
464
+ }
465
+ layer {
466
+ name: "relu7_3"
467
+ type: "ReLU"
468
+ bottom: "conv7_3"
469
+ top: "conv7_3"
470
+ }
471
+ layer {
472
+ name: "conv7_3norm"
473
+ type: "BatchNorm"
474
+ bottom: "conv7_3"
475
+ top: "conv7_3norm"
476
+ batch_norm_param{ }
477
+ param {lr_mult: 0 decay_mult: 0}
478
+ param {lr_mult: 0 decay_mult: 0}
479
+ param {lr_mult: 0 decay_mult: 0}
480
+ }
481
+ # *****************
482
+ # ***** conv8 *****
483
+ # *****************
484
+ layer {
485
+ name: "conv8_1"
486
+ type: "Deconvolution"
487
+ bottom: "conv7_3norm"
488
+ top: "conv8_1"
489
+ convolution_param {
490
+ num_output: 256
491
+ kernel_size: 4
492
+ pad: 1
493
+ dilation: 1
494
+ stride: 2
495
+ }
496
+ }
497
+ layer {
498
+ name: "relu8_1"
499
+ type: "ReLU"
500
+ bottom: "conv8_1"
501
+ top: "conv8_1"
502
+ }
503
+ layer {
504
+ name: "conv8_2"
505
+ type: "Convolution"
506
+ bottom: "conv8_1"
507
+ top: "conv8_2"
508
+ convolution_param {
509
+ num_output: 256
510
+ kernel_size: 3
511
+ pad: 1
512
+ dilation: 1
513
+ }
514
+ }
515
+ layer {
516
+ name: "relu8_2"
517
+ type: "ReLU"
518
+ bottom: "conv8_2"
519
+ top: "conv8_2"
520
+ }
521
+ layer {
522
+ name: "conv8_3"
523
+ type: "Convolution"
524
+ bottom: "conv8_2"
525
+ top: "conv8_3"
526
+ convolution_param {
527
+ num_output: 256
528
+ kernel_size: 3
529
+ pad: 1
530
+ dilation: 1
531
+ }
532
+ }
533
+ layer {
534
+ name: "relu8_3"
535
+ type: "ReLU"
536
+ bottom: "conv8_3"
537
+ top: "conv8_3"
538
+ }
539
+ # *******************
540
+ # ***** Softmax *****
541
+ # *******************
542
+ layer {
543
+ name: "conv8_313"
544
+ type: "Convolution"
545
+ bottom: "conv8_3"
546
+ top: "conv8_313"
547
+ convolution_param {
548
+ num_output: 313
549
+ kernel_size: 1
550
+ stride: 1
551
+ dilation: 1
552
+ }
553
+ }
554
+ layer {
555
+ name: "conv8_313_rh"
556
+ type: "Scale"
557
+ bottom: "conv8_313"
558
+ top: "conv8_313_rh"
559
+ scale_param {
560
+ bias_term: false
561
+ filler { type: 'constant' value: 2.606 }
562
+ }
563
+ }
564
+ layer {
565
+ name: "class8_313_rh"
566
+ type: "Softmax"
567
+ bottom: "conv8_313_rh"
568
+ top: "class8_313_rh"
569
+ }
570
+ # ********************
571
+ # ***** Decoding *****
572
+ # ********************
573
+ layer {
574
+ name: "class8_ab"
575
+ type: "Convolution"
576
+ bottom: "class8_313_rh"
577
+ top: "class8_ab"
578
+ convolution_param {
579
+ num_output: 2
580
+ kernel_size: 1
581
+ stride: 1
582
+ dilation: 1
583
+ }
584
+ }
585
+ layer {
586
+ name: "Silence"
587
+ type: "Silence"
588
+ bottom: "class8_ab"
589
+ }
models/pts_in_hull.npy ADDED
Binary file (5.09 kB). View file