- README.md +8 -2
- utils/yolo_utils.py +6 -16
README.md
CHANGED
@@ -10,7 +10,11 @@ pinned: false
|
|
10 |
|
11 |
|
12 |
# YOLOv8-TO
|
13 |
-
Code for the
|
|
|
|
|
|
|
|
|
14 |
|
15 |
## Table of Contents
|
16 |
- [Overview](#overview)
|
@@ -26,7 +30,9 @@ Code for the article "From Density to Geometry: YOLOv8 Instance Segmentation for
|
|
26 |
Brief description of what the project does and the problem it solves. Include a link or reference to the original article that inspired or is associated with this implementation.
|
27 |
|
28 |
## Demo
|
29 |
-
|
|
|
|
|
30 |
|
31 |
## Reference
|
32 |
This code aims to reproduce the results presented in the research article:
|
|
|
10 |
|
11 |
|
12 |
# YOLOv8-TO
|
13 |
+
Code for the paper:
|
14 |
+
> "From Density to Geometry: YOLOv8 Instance Segmentation for Reverse Engineering of Optimized Structures"
|
15 |
+
|
16 |
+
- Read the paper: [arXiv](https://arxiv.org/abs/2404.18763).
|
17 |
+
- Try it out here: [Demo](https://huggingface.co/spaces/tomrb/YOLOv8-TO)
|
18 |
|
19 |
## Table of Contents
|
20 |
- [Overview](#overview)
|
|
|
30 |
Brief description of what the project does and the problem it solves. Include a link or reference to the original article that inspired or is associated with this implementation.
|
31 |
|
32 |
## Demo
|
33 |
+
The nano version of the model is hosted on **Hugging Face Spaces**:
|
34 |
+
|
35 |
+
- [Try the YOLOv8-TO Nano model with your own images!](https://huggingface.co/spaces/tomrb/YOLOv8-TO)
|
36 |
|
37 |
## Reference
|
38 |
This code aims to reproduce the results presented in the research article:
|
utils/yolo_utils.py
CHANGED
@@ -2,7 +2,12 @@ import torch
|
|
2 |
import numpy as np
|
3 |
import torch.nn.functional as F
|
4 |
import torch.nn as nn
|
|
|
|
|
|
|
|
|
5 |
|
|
|
6 |
|
7 |
class CustomTverskyLoss(nn.Module):
|
8 |
def __init__(self, alpha=0.1, beta=0.9, size_average=True):
|
@@ -124,14 +129,6 @@ def calc_Phi(variable, LSgrid):
|
|
124 |
|
125 |
# utils.py
|
126 |
|
127 |
-
import torch
|
128 |
-
import numpy as np
|
129 |
-
from PIL import Image
|
130 |
-
import matplotlib.pyplot as plt
|
131 |
-
from matplotlib.colors import TwoSlopeNorm
|
132 |
-
|
133 |
-
from PIL import Image
|
134 |
-
|
135 |
def preprocess_image_pil(image, threshold_value=0.9, upscale=False, upscale_factor=2.0):
|
136 |
# Ensure the image is in grayscale mode
|
137 |
if image.mode != 'L':
|
@@ -257,11 +254,6 @@ def plot_results(input_image_array_tensor, seg_result, pred_Phi, sum_pred_H, fin
|
|
257 |
|
258 |
fig.savefig(filename, dpi=600)
|
259 |
|
260 |
-
|
261 |
-
import numpy as np
|
262 |
-
from PIL import Image
|
263 |
-
import io
|
264 |
-
|
265 |
def plot_results_gradio(input_image_array_tensor, seg_result, pred_Phi, sum_pred_H, final_H, dice_loss, tversky_loss):
|
266 |
nelx = input_image_array_tensor.shape[1] - 1
|
267 |
nely = input_image_array_tensor.shape[0] - 1
|
@@ -284,9 +276,7 @@ def plot_results_gradio(input_image_array_tensor, seg_result, pred_Phi, sum_pred
|
|
284 |
axes[1, 0].imshow(np.flipud(sum_pred_H.detach().numpy().reshape((nely+1, nelx+1), order='F')), origin='lower', cmap='gray_r')
|
285 |
axes[1, 0].set_title('Prediction Projection')
|
286 |
|
287 |
-
plt.subplots_adjust(hspace=0.3, wspace=0.01)
|
288 |
-
plt.figtext(0.5, 0.05, f'Dice Loss: {dice_loss.item():.4f}', ha='center', fontsize=16)
|
289 |
-
|
290 |
# Convert figure to a PIL Image
|
291 |
buf = io.BytesIO()
|
292 |
plt.savefig(buf, format='png')
|
|
|
2 |
import numpy as np
|
3 |
import torch.nn.functional as F
|
4 |
import torch.nn as nn
|
5 |
+
from PIL import Image
|
6 |
+
import io
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
from matplotlib.colors import TwoSlopeNorm
|
9 |
|
10 |
+
from PIL import Image
|
11 |
|
12 |
class CustomTverskyLoss(nn.Module):
|
13 |
def __init__(self, alpha=0.1, beta=0.9, size_average=True):
|
|
|
129 |
|
130 |
# utils.py
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
def preprocess_image_pil(image, threshold_value=0.9, upscale=False, upscale_factor=2.0):
|
133 |
# Ensure the image is in grayscale mode
|
134 |
if image.mode != 'L':
|
|
|
254 |
|
255 |
fig.savefig(filename, dpi=600)
|
256 |
|
|
|
|
|
|
|
|
|
|
|
257 |
def plot_results_gradio(input_image_array_tensor, seg_result, pred_Phi, sum_pred_H, final_H, dice_loss, tversky_loss):
|
258 |
nelx = input_image_array_tensor.shape[1] - 1
|
259 |
nely = input_image_array_tensor.shape[0] - 1
|
|
|
276 |
axes[1, 0].imshow(np.flipud(sum_pred_H.detach().numpy().reshape((nely+1, nelx+1), order='F')), origin='lower', cmap='gray_r')
|
277 |
axes[1, 0].set_title('Prediction Projection')
|
278 |
|
279 |
+
plt.subplots_adjust(hspace=0.3, wspace=0.01)
|
|
|
|
|
280 |
# Convert figure to a PIL Image
|
281 |
buf = io.BytesIO()
|
282 |
plt.savefig(buf, format='png')
|