Spaces:
Runtime error
Runtime error
Commit
•
fa338f0
1
Parent(s):
de3d7fa
'imagecolorization'
Browse files- image_colorization.py +51 -0
- models/image-colorization.h5 +3 -0
- streamlit_app.py +6 -1
image_colorization.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
from tensorflow.keras.utils import img_to_array, load_img
|
6 |
+
from skimage.transform import resize
|
7 |
+
from skimage.io import imsave, imshow
|
8 |
+
from skimage.color import rgb2lab, lab2rgb
|
9 |
+
|
10 |
+
def main_colorization():
|
11 |
+
|
12 |
+
st.header("Image Colorization")
|
13 |
+
model = tf.keras.models.load_model("models/image-colorization.h5")
|
14 |
+
|
15 |
+
image_file = st.file_uploader(
|
16 |
+
"Upload image for testing", type=['jpeg', 'png', 'jpg', 'webp'])
|
17 |
+
|
18 |
+
|
19 |
+
if st.button("Process"):
|
20 |
+
image = Image.open(image_file)
|
21 |
+
h,w = 256,256
|
22 |
+
|
23 |
+
img1_color=[]
|
24 |
+
|
25 |
+
img1 = img_to_array(image)
|
26 |
+
img1 = resize(img1 ,(256,256))
|
27 |
+
img1_color.append(img1)
|
28 |
+
|
29 |
+
img1_color = np.array(img1_color, dtype=float)
|
30 |
+
img1_color = rgb2lab(1.0/255*img1_color)[:,:,:,0]
|
31 |
+
img1_color = img1_color.reshape(img1_color.shape+(1,))
|
32 |
+
output1 = model.predict(img1_color)
|
33 |
+
output1 = output1*128
|
34 |
+
|
35 |
+
result = np.zeros((256, 256, 3))
|
36 |
+
result[:,:,0] = img1_color[0][:,:,0]
|
37 |
+
result[:,:,1:] = output1[0]
|
38 |
+
col1, col2 = st.columns([1,1])
|
39 |
+
image = image.resize((h,w))
|
40 |
+
|
41 |
+
with col1:
|
42 |
+
st.text("Original Image")
|
43 |
+
st.image(image)
|
44 |
+
with col2 :
|
45 |
+
st.text("Colourful Image")
|
46 |
+
st.image(resize(lab2rgb(result),(256,256)))
|
47 |
+
|
48 |
+
st.write("Image Colorization Notebook [link](https://github.com/bozkurtmert0/deep-learning-projects/blob/main/Image_Colorization.ipynb)")
|
49 |
+
|
50 |
+
if __name__ == '__main__':
|
51 |
+
main_colorization()
|
models/image-colorization.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5970a02141fa41203f01c4e9df0b1c250779facf6be59513fbf93c0d7fecc1a0
|
3 |
+
size 17807024
|
streamlit_app.py
CHANGED
@@ -5,6 +5,7 @@ from face_detec import main_face
|
|
5 |
from movie_rec import main_movie
|
6 |
from disaster_twet import main_twet
|
7 |
from catvsdog import main_catvsdog
|
|
|
8 |
|
9 |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
10 |
# -------------------------------------------------------------------------------------------------------------
|
@@ -17,7 +18,7 @@ def main():
|
|
17 |
st.sidebar.write("")
|
18 |
st.sidebar.subheader("Select an option")
|
19 |
activities = [
|
20 |
-
"Cats vs Dogs", "Disaster Tweet Classification", "Movie Recommender", "Face Detection"]
|
21 |
choice = st.sidebar.selectbox("", activities)
|
22 |
|
23 |
# ------------Cats Vs Dogs ----------------------------------------------------------------
|
@@ -34,6 +35,10 @@ def main():
|
|
34 |
# -------------------------------------------------------------------------------
|
35 |
if choice == "Face Detection":
|
36 |
main_face()
|
|
|
|
|
|
|
|
|
37 |
|
38 |
if __name__ == '__main__':
|
39 |
main()
|
|
|
5 |
from movie_rec import main_movie
|
6 |
from disaster_twet import main_twet
|
7 |
from catvsdog import main_catvsdog
|
8 |
+
from image_colorization import main_colorization
|
9 |
|
10 |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
11 |
# -------------------------------------------------------------------------------------------------------------
|
|
|
18 |
st.sidebar.write("")
|
19 |
st.sidebar.subheader("Select an option")
|
20 |
activities = [
|
21 |
+
"Cats vs Dogs", "Disaster Tweet Classification", "Movie Recommender", "Face Detection","Image Colorization"]
|
22 |
choice = st.sidebar.selectbox("", activities)
|
23 |
|
24 |
# ------------Cats Vs Dogs ----------------------------------------------------------------
|
|
|
35 |
# -------------------------------------------------------------------------------
|
36 |
if choice == "Face Detection":
|
37 |
main_face()
|
38 |
+
#-----------------------------------------------------------------------
|
39 |
+
if choice == "Image Colorization":
|
40 |
+
main_colorization()
|
41 |
+
|
42 |
|
43 |
if __name__ == '__main__':
|
44 |
main()
|