geekyrakshit commited on
Commit
12456dc
1 Parent(s): 6f29089

integrated zero-dce with the apps

Browse files
Files changed (2) hide show
  1. app.py +49 -11
  2. enhance_me/__init__.py +2 -0
app.py CHANGED
@@ -1,23 +1,36 @@
 
1
  from PIL import Image
2
  import streamlit as st
3
  from tensorflow.keras import utils, backend
4
 
5
- from enhance_me.mirnet import MIRNet
6
 
7
 
8
  def get_mirnet_object() -> MIRNet:
9
- mirnet = MIRNet()
10
- mirnet.build_model()
11
  utils.get_file(
12
  "weights_lol_128.h5",
13
  "https://github.com/soumik12345/enhance-me/releases/download/v0.2/weights_lol_128.h5",
14
  cache_dir=".",
15
  cache_subdir="weights",
16
  )
 
 
17
  mirnet.load_weights("./weights/weights_lol_128.h5")
18
  return mirnet
19
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def main():
22
  st.markdown("# Enhance Me")
23
  st.markdown("Made with :heart: by [geekyRakshit](http://github.com/soumik12345)")
@@ -30,14 +43,39 @@ def main():
30
  if uploaded_file is not None:
31
  original_image = Image.open(uploaded_file)
32
  st.image(original_image, caption="original image")
33
- st.sidebar.info("Loading MIRNet...")
34
- mirnet = get_mirnet_object()
35
- st.sidebar.info("Done!")
36
- st.sidebar.info("Processing Image...")
37
- enhanced_image = mirnet.infer(original_image)
38
- st.sidebar.info("Done!")
39
- st.image(enhanced_image, caption="enhanced image")
40
- backend.clear_session()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
 
43
  if __name__ == "__main__":
 
1
+ import os
2
  from PIL import Image
3
  import streamlit as st
4
  from tensorflow.keras import utils, backend
5
 
6
+ from enhance_me import MIRNet, ZeroDCE
7
 
8
 
9
  def get_mirnet_object() -> MIRNet:
 
 
10
  utils.get_file(
11
  "weights_lol_128.h5",
12
  "https://github.com/soumik12345/enhance-me/releases/download/v0.2/weights_lol_128.h5",
13
  cache_dir=".",
14
  cache_subdir="weights",
15
  )
16
+ mirnet = MIRNet()
17
+ mirnet.build_model()
18
  mirnet.load_weights("./weights/weights_lol_128.h5")
19
  return mirnet
20
 
21
 
22
+ def get_zero_dce_object(model_alias: str) -> ZeroDCE:
23
+ utils.get_file(
24
+ f"{model_alias}.h5",
25
+ f"https://github.com/soumik12345/enhance-me/releases/download/v0.4/{model_alias}.h5",
26
+ cache_dir=".",
27
+ cache_subdir="weights",
28
+ )
29
+ dce = ZeroDCE()
30
+ dce.load_weights(os.path.join("./weights", f"{model_alias}.h5"))
31
+ return dce
32
+
33
+
34
  def main():
35
  st.markdown("# Enhance Me")
36
  st.markdown("Made with :heart: by [geekyRakshit](http://github.com/soumik12345)")
 
43
  if uploaded_file is not None:
44
  original_image = Image.open(uploaded_file)
45
  st.image(original_image, caption="original image")
46
+ model_option = st.sidebar.selectbox(
47
+ "Please select the model:",
48
+ (
49
+ "",
50
+ "MIRNet",
51
+ "Zero-DCE (dce_weights_lol_128)",
52
+ "Zero-DCE (dce_weights_lol_128_resize)",
53
+ "Zero-DCE (dce_weights_lol_256)",
54
+ "Zero-DCE (dce_weights_lol_256_resize)",
55
+ "Zero-DCE (dce_weights_unpaired_128)",
56
+ "Zero-DCE (dce_weights_unpaired_128_resize)",
57
+ "Zero-DCE (dce_weights_unpaired_256)",
58
+ "Zero-DCE (dce_weights_unpaired_256_resize)"
59
+ ),
60
+ )
61
+ if model_option != "":
62
+ if model_option == "MIRNet":
63
+ st.sidebar.info("Loading MIRNet...")
64
+ mirnet = get_mirnet_object()
65
+ st.sidebar.info("Done!")
66
+ st.sidebar.info("Processing Image...")
67
+ enhanced_image = mirnet.infer(original_image)
68
+ st.sidebar.info("Done!")
69
+ st.image(enhanced_image, caption="enhanced image")
70
+ elif "Zero-DCE" in model_option:
71
+ model_alias = model_option[model_option.find("(") + 1: model_option.find(")")]
72
+ st.sidebar.info("Loading Zero-DCE...")
73
+ zero_dce = get_zero_dce_object(model_alias)
74
+ st.sidebar.info("Done!")
75
+ enhanced_image = zero_dce.infer(original_image)
76
+ st.sidebar.info("Done!")
77
+ st.image(enhanced_image, caption="enhanced image")
78
+ backend.clear_session()
79
 
80
 
81
  if __name__ == "__main__":
enhance_me/__init__.py CHANGED
@@ -0,0 +1,2 @@
 
 
 
1
+ from .mirnet import MIRNet
2
+ from .zero_dce import ZeroDCE