import io
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from tensorflow.keras import layers
from tensorflow.keras.models import load_model
def load_image(image_path):
"""Loads and preprocesses an image for the model.
Args:
image_path: The path to the image to load.
Returns:
A preprocessed numpy array representing the image.
"""
Load the image from disk.
image = tf.io.read_file(image_path)
Decode the image from a JPEG string to a 3D tensor.
image = tf.image.decode_jpeg(image, channels=3)
Resize the image to the desired size.
image = tf.image.resize(image, [224, 224])
Normalize the pixel values between 0 and 1.
image = image / 255.0
Convert the image to a float32 data type.
image = tf.cast(image, tf.float32)
Remove the batch dimension.
image = image[tf.newaxis, ...]
return image
def get_before_after_images(before_image_path, after_image_path):
"""Loads before and after images for comparison
Args:
before_image_path: The path to the before image.
after_image_path: The path to the after image.
Returns:
A tuple containing two preprocessed numpy arrays representing the before and after images.
"""
Load the before and after images.
before_image = load_image(before_image_path)
after_image = load_image(after_image_path)
return before_image, after_image
def display_after_image(after_image, output_path: io.BytesIO):
"""Displays the after image.
Args:
after_image: The preprocessed after image.
output_path: The output path for the image.
"""
after = np.clip(after_image[0, ...] 255.0, 0.0, 255.0).astype(np.uint8)
output_path.write(np.transpose(after, [1, 0, 2]))
output_path.seek(0)
display(Image(output_path))
def plot_before_after_images(
before_image, after_image, output_path: io.BytesIO
):
"""Plots the before and after images sidebyside.
Args:
before_image: The preprocessed before image.
after_image: The preprocessed after image.
output_path: The output path for the image.
"""
Create a figure with two subplots.
fig, ax = plt.subplots(1, 2, figsize=(15, 15))
Plot the before image in the first subplot.
ax[0].imshow(before_image[0, ..., ::1])
ax[0].set_title("Before")
Plot the after image in the second subplot.
ax[1].imshow(after_image[0, ..., ::1])
ax[1].set_title("After")
Remove the axes labels.
ax[0].set_xticks([])
ax[0].set_yticks([])
ax[1].set_xticks([])
ax[1].set_yticks([])
Save the figure to the output path.
fig.savefig(output_path)
plt.close(fig)
def predict_image(image_path, before_image_path):
"""Predicts the after image using the trained model.
Args:
image_path: The path to the input image.
before_image_path: The path to the before image.
"""
Load the base model, which is a VGG16 model pretrained on ImageNet.
base_model = tf.keras.applications.VGG16(
weights="imagenet", include_top=False, input_shape=(224, 224, 3)
)
Freeze the weights of the base model.
base_model.trainable = False
Add a new layer on top of the base model.
inputs = layers.Input(shape=(224, 224, 3))
x = base_model(inputs)
outputs = layers.Conv2D(3, (1, 1), activation="sigmoid")(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)
Load the weights of the trained model.
model.load_weights("model.h5")
Load the before and after images.
before_image, after_image = get_before_after_images(before_image_path, image_path)
Predict the after image.
predicted_after_image = model.predict(before_image)
Display the after image.
display_after_image(predicted_after_image, output_path)
Plot the before and after images sidebyside and save it.
plot_before_after_images(before_image, predicted_after_image, output_path)
塌鼻梁隆鼻效果
塌鼻梁隆鼻的效果是显着的,可以改善鼻梁高度和鼻尖形状,塑造出更立体、精致的鼻型。
隆鼻价格
塌鼻梁隆鼻的价格因手术方式、材料和医院而异,一般在以下范围内:
注射隆鼻:元
硅胶假体隆鼻:元
自体软骨隆鼻:元
影响价格的因素
手术方式:注射隆鼻是最便宜的,但效果维持时间较短;自体软骨隆鼻是最昂贵的,但效果最自然、持久。
材料:硅胶假体比自体软骨便宜,但有排异反应的风险。
医院级别:三甲医院收费高于二级医院。
医生技术:经验丰富、技术精湛的医生收费更高。
术后注意事项
术后避免剧烈运动和挤压鼻子。
保持伤口清洁干燥,避免感染。
遵医嘱定期复查,观察恢复情况。