AIOmarRehan commited on
Commit
923b2e0
·
verified ·
1 Parent(s): 7fcfa16

Upload 6 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* 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
 
 
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
36
+ Results/A_U-Net_Autoencoder.mp4 filter=lfs diff=lfs merge=lfs -text
Backend/U-NET.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import io
3
+ from flask import Flask, request, jsonify, send_file
4
+ from flask_cors import CORS
5
+ from tensorflow.keras.models import load_model
6
+ from PIL import Image
7
+
8
+ # Load model
9
+ model = load_model("unet_model.h5", compile = False)
10
+
11
+ app = Flask(__name__)
12
+ CORS(app) # allow frontend to fetch
13
+
14
+ # Preprocess function
15
+ def preprocess_image(image, target_size = (192, 176)):
16
+ image = image.resize((target_size[1], target_size[0])) # width, height
17
+ image = np.array(image) / 255.0
18
+ if image.ndim == 2:
19
+ image = np.expand_dims(image, axis = -1)
20
+ return np.expand_dims(image, axis = 0)
21
+
22
+ @app.route("/predict", methods=["POST"])
23
+ def predict():
24
+ if "file" not in request.files:
25
+ return jsonify({"error": "No file uploaded"}), 400
26
+
27
+ file = request.files["file"]
28
+ img = Image.open(file.stream).convert("L") # grayscale
29
+
30
+ input_data = preprocess_image(img)
31
+
32
+ pred = model.predict(input_data)[0]
33
+
34
+ if pred.ndim == 3 and pred.shape[-1] == 1:
35
+ pred = np.squeeze(pred, axis = -1)
36
+
37
+ pred_img = (pred * 255).astype(np.uint8)
38
+ pred_img = Image.fromarray(pred_img)
39
+
40
+ buf = io.BytesIO()
41
+ pred_img.save(buf, format="PNG")
42
+ buf.seek(0)
43
+ return send_file(buf, mimetype = "image/png")
44
+
45
+ if __name__ == "__main__":
46
+ app.run(host = "127.0.0.1", port = 5000, debug = True)
Backend/static/index.html ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>U-Net Segmentation</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ </head>
9
+ <body>
10
+
11
+ <h1>U-Net Image Denoising</h1>
12
+
13
+ <div class="upload-area" id="uploadArea">
14
+ <p>Drag & Drop your image here or click to browse</p>
15
+ <input type="file" id="fileInput" accept="image/*" hidden>
16
+ </div>
17
+
18
+ <div class="preview" id="preview"></div>
19
+
20
+ <button id="runBtn">Run Image Denoising</button>
21
+ <div class="loader" id="loader"></div>
22
+
23
+ <div class="result" id="result"></div>
24
+
25
+ <script src="script.js"></script>
26
+ </body>
27
+ </html>
Backend/static/script.js ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const uploadArea = document.getElementById("uploadArea");
2
+ const fileInput = document.getElementById("fileInput");
3
+ const preview = document.getElementById("preview");
4
+ const runBtn = document.getElementById("runBtn");
5
+ const loader = document.getElementById("loader");
6
+ const result = document.getElementById("result");
7
+
8
+ let uploadedFile = null;
9
+
10
+ // Open file browser on click
11
+ uploadArea.addEventListener("click", () => fileInput.click());
12
+
13
+ // Handle file input
14
+ fileInput.addEventListener("change", (e) => {
15
+ uploadedFile = e.target.files[0];
16
+ showPreview(uploadedFile);
17
+ });
18
+
19
+ // Drag & drop
20
+ uploadArea.addEventListener("dragover", (e) => {
21
+ e.preventDefault();
22
+ uploadArea.style.background = "rgba(79,195,247,0.2)";
23
+ });
24
+
25
+ uploadArea.addEventListener("dragleave", () => {
26
+ uploadArea.style.background = "rgba(255,255,255,0.05)";
27
+ });
28
+
29
+ uploadArea.addEventListener("drop", (e) => {
30
+ e.preventDefault();
31
+ uploadedFile = e.dataTransfer.files[0];
32
+ showPreview(uploadedFile);
33
+ });
34
+
35
+ function showPreview(file) {
36
+ if (!file) return;
37
+ const reader = new FileReader();
38
+ reader.onload = (e) => {
39
+ preview.innerHTML = `<img src="${e.target.result}" alt="Preview">`;
40
+ };
41
+ reader.readAsDataURL(file);
42
+ }
43
+
44
+ runBtn.addEventListener("click", async () => {
45
+ if (!uploadedFile) {
46
+ alert("Please upload an image first!");
47
+ return;
48
+ }
49
+
50
+ loader.style.display = "block";
51
+ result.innerHTML = "";
52
+
53
+ const formData = new FormData();
54
+ formData.append("file", uploadedFile);
55
+
56
+ try {
57
+ const response = await fetch("http://127.0.0.1:5000/predict", {
58
+ method: "POST",
59
+ body: formData,
60
+ });
61
+
62
+ if (!response.ok) throw new Error("Failed to fetch result from backend.");
63
+
64
+ const blob = await response.blob();
65
+ const url = URL.createObjectURL(blob);
66
+
67
+ loader.style.display = "none";
68
+ result.innerHTML = `
69
+ <div>
70
+ <h3>Original</h3>
71
+ <img src="${URL.createObjectURL(uploadedFile)}" alt="Original">
72
+ </div>
73
+ <div>
74
+ <h3>Denoised Image</h3>
75
+ <img src="${url}" alt="Denoised Image">
76
+ </div>
77
+ `;
78
+
79
+ } catch (err) {
80
+ loader.style.display = "none";
81
+ alert(err.message);
82
+ }
83
+ });
Backend/static/style.css ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
3
+ background: linear-gradient(135deg, #141e30, #243b55);
4
+ color: #fff;
5
+ text-align: center;
6
+ padding: 30px;
7
+ }
8
+
9
+ h1 {
10
+ font-size: 2.5rem;
11
+ margin-bottom: 20px;
12
+ }
13
+
14
+ .upload-area {
15
+ border: 2px dashed #4fc3f7;
16
+ border-radius: 20px;
17
+ padding: 40px;
18
+ margin: 20px auto;
19
+ width: 70%;
20
+ max-width: 600px;
21
+ cursor: pointer;
22
+ transition: 0.3s;
23
+ background: rgba(255, 255, 255, 0.05);
24
+ }
25
+
26
+ .upload-area:hover {
27
+ background: rgba(79, 195, 247, 0.1);
28
+ transform: scale(1.02);
29
+ }
30
+
31
+ .preview {
32
+ margin-top: 20px;
33
+ }
34
+
35
+ .preview img {
36
+ max-width: 300px;
37
+ border-radius: 12px;
38
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
39
+ }
40
+
41
+ button {
42
+ background: #4fc3f7;
43
+ border: none;
44
+ padding: 12px 24px;
45
+ margin-top: 20px;
46
+ border-radius: 30px;
47
+ color: #fff;
48
+ font-size: 1.1rem;
49
+ cursor: pointer;
50
+ transition: 0.3s;
51
+ }
52
+
53
+ button:hover {
54
+ background: #039be5;
55
+ }
56
+
57
+ .result {
58
+ display: flex;
59
+ justify-content: center;
60
+ gap: 30px;
61
+ margin-top: 40px;
62
+ flex-wrap: wrap;
63
+ }
64
+
65
+ .result img {
66
+ max-width: 350px;
67
+ border-radius: 12px;
68
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
69
+ }
70
+
71
+ .loader {
72
+ display: none;
73
+ margin-top: 20px;
74
+ border: 6px solid #f3f3f3;
75
+ border-top: 6px solid #4fc3f7;
76
+ border-radius: 50%;
77
+ width: 40px;
78
+ height: 40px;
79
+ animation: spin 1s linear infinite;
80
+ margin-left: auto;
81
+ margin-right: auto;
82
+ }
83
+
84
+ @keyframes spin {
85
+ 0% { transform: rotate(0deg); }
86
+ 100% { transform: rotate(360deg); }
87
+ }
Notebook/A_U_Net_Based_CNN_Autoencoder_for_Preprocessing_Noisy_Images_in_Classification_Tasks.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
Results/A_U-Net_Autoencoder.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:076748cdbeb1edef5da3d59610802675e1c9f3164e3267be4cddd69408d39af4
3
+ size 6695182