Spaces:
Sleeping
Sleeping
Commit
·
40bdd20
1
Parent(s):
47cc597
´´ver2´´
Browse files
app.py
CHANGED
@@ -4,25 +4,23 @@ import numpy as np
|
|
4 |
import gradio as gr
|
5 |
import cv2
|
6 |
|
|
|
|
|
|
|
7 |
# Carrega o modelo de transferência de estilo pré-treinado
|
8 |
style_transfer_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
|
9 |
|
10 |
def load_image(image):
|
11 |
-
#
|
|
|
|
|
|
|
12 |
image = image.astype(np.float32)[np.newaxis, ...] / 255.
|
13 |
if image.shape[-1] == 4:
|
14 |
image = image[..., :3]
|
15 |
return image
|
16 |
|
17 |
-
|
18 |
-
return baseline + alpha * (target - baseline)
|
19 |
-
|
20 |
-
def apply_sharpness(image, intensity):
|
21 |
-
kernel = np.array([[0, -intensity, 0],
|
22 |
-
[-intensity, 1 + 4 * intensity, -intensity],
|
23 |
-
[0, -intensity, 0]])
|
24 |
-
sharp_image = cv2.filter2D(image, -1, kernel)
|
25 |
-
return np.clip(sharp_image, 0, 255)
|
26 |
|
27 |
def style_transfer(content_image, style_image, style_density, content_sharpness):
|
28 |
# Processa as imagens
|
@@ -36,6 +34,7 @@ def style_transfer(content_image, style_image, style_density, content_sharpness)
|
|
36 |
# Executa a transferência de estilo
|
37 |
stylized_image = style_transfer_model(tf.constant(content_image_sharp), tf.constant(style_image))[0]
|
38 |
|
|
|
39 |
# Interpola entre a imagem de conteúdo e a imagem estilizada para densidade de estilo
|
40 |
stylized_image = interpolate_images(
|
41 |
baseline=content_image[0],
|
|
|
4 |
import gradio as gr
|
5 |
import cv2
|
6 |
|
7 |
+
# Tamanho padrão para o redimensionamento das imagens
|
8 |
+
IMAGE_SIZE = (256, 256)
|
9 |
+
|
10 |
# Carrega o modelo de transferência de estilo pré-treinado
|
11 |
style_transfer_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
|
12 |
|
13 |
def load_image(image):
|
14 |
+
# Redimensiona a imagem para o tamanho padrão
|
15 |
+
image = cv2.resize(image, IMAGE_SIZE, interpolation=cv2.INTER_AREA)
|
16 |
+
|
17 |
+
# Processa a imagem para o modelo
|
18 |
image = image.astype(np.float32)[np.newaxis, ...] / 255.
|
19 |
if image.shape[-1] == 4:
|
20 |
image = image[..., :3]
|
21 |
return image
|
22 |
|
23 |
+
# Restante do seu código...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
def style_transfer(content_image, style_image, style_density, content_sharpness):
|
26 |
# Processa as imagens
|
|
|
34 |
# Executa a transferência de estilo
|
35 |
stylized_image = style_transfer_model(tf.constant(content_image_sharp), tf.constant(style_image))[0]
|
36 |
|
37 |
+
# Não é mais necessário redimensionar stylized_image, pois todas as imagens já estão no mesmo tamanho
|
38 |
# Interpola entre a imagem de conteúdo e a imagem estilizada para densidade de estilo
|
39 |
stylized_image = interpolate_images(
|
40 |
baseline=content_image[0],
|