efghi7890 commited on
Commit
6f5fe00
·
1 Parent(s): 5e2bab0

Upload 6 files

Browse files
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from PIL import Image
5
+ from tensorflow import keras
6
+ from tensorflow.keras.applications.resnet50 import preprocess_input
7
+
8
+ autoencoder = keras.models.load_model("D:/midterm/autoencoder/models/denoising_autoencoder_weights.h5")
9
+ encoder = keras.models.load_model("D:/midterm/autoencoder/models/encoder.h5")
10
+ decoder = keras.models.load_model("D:/midterm/autoencoder/models/decoder.h5")
11
+
12
+
13
+ # Define the Gradio interface
14
+ def denoise_image(input_image):
15
+ # Open the image
16
+ input_image= np.resize(input_image,(32,32,3))
17
+ input_array = np.array(input_image)
18
+ input_array = preprocess_input(input_array)
19
+ input_array = np.expand_dims(input_array, axis=0)
20
+ hash = encoder.predict(input_array)
21
+ output = decoder.predict(hash)
22
+ hash_image = Image.fromarray((hash[0].reshape(32,32) * 255).astype(np.uint8))
23
+ output_image = Image.fromarray((output[0] * 255).astype(np.uint8))
24
+ return [input_image, hash_image, output_image]
25
+
26
+ iface = gr.Interface(
27
+ fn=denoise_image,
28
+ inputs= [
29
+ gr.Image (label = "Original Image")
30
+ ],
31
+ outputs=[
32
+ gr.Image (label = "Decoded Output"),
33
+ gr.Image (label= "Hash Output"),
34
+ ],
35
+ title="Denoising Autoencoder",
36
+ description="Upload an image and see its denoised version using a denoising autoencoder.",
37
+ examples=[
38
+ ["D:/midterm/autoencoder/example.jpg"]
39
+ ],
40
+ )
41
+
42
+ iface.launch(share = True, server_port=3001)
example.jpg ADDED
models/decoder.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31b9f9c61821bfb9d11ea704ea678fc54ac832707eb904e3f1bd9c47fe310959
3
+ size 53152
models/denoising_autoencoder_weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c862437b0e1ca05565a9fc022aca396ed080d56b3e339a6ee5637a7167a7db8c
3
+ size 212960
models/encoder.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ef0f37772624e096970712fe43224ea648f44622a814f44d24c6235dccf20fd
3
+ size 41224
requirements.txt.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ tensorflow
2
+ Pillow