当前位置: 首页 > news >正文

网站后台上传图片 不可用淘宝客网站一般用什么做的

网站后台上传图片 不可用,淘宝客网站一般用什么做的,青海贸易网站建设公司,南京网准备 官方教程#xff1a; 任意风格的快速风格转换 模型下载地址#xff1a; https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2 学习 加载要处理的内容图片和风格图片 # 用于将图像裁剪为方形def crop_center(image):# 图片原始形状shape image…准备 官方教程 任意风格的快速风格转换 模型下载地址 https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2 学习 加载要处理的内容图片和风格图片 # 用于将图像裁剪为方形def crop_center(image):# 图片原始形状shape image.shape# 新形状new_shape min(shape[1], shape[2])offset_y max(shape[1]-shape[2], 0) // 2offset_x max(shape[2]-shape[1], 0) // 2# 返回新图片image tf.image.crop_to_bounding_box(image, offset_y, offset_x, new_shape, new_shape)return image# 加载并预处理图片def load_image(image_url, image_size(256, 256), preserve_aspect_ratioTrue):# 缓存图像文件image_path tf.keras.utils.get_file(os.path.basename(image_url)[-128:], image_url)# 加载并转换为float32 numpy数组添加批次维度并规范化为范围[01]。img tf.io.decode_image(tf.io.read_file(image_path),channels3, dtypetf.float32)[tf.newaxis, ...]img crop_center(img)img tf.image.resize(img, image_size, preserve_aspect_ratioTrue)return img# 展示图片def show_n(images, titles(,)):n len(images)image_sizes [image.shape[1] for image in images]w (image_sizes[0] * 6) // 320plt.figure(figsize(w * n, w))gs gridspec.GridSpec(1, n, width_ratiosimage_sizes)for i in range(n):plt.subplot(gs[i])plt.imshow(images[i][0], aspectequal)plt.axis(off)plt.title(titles[i] if len(titles) i else )plt.show()content_image_url https://scpic3.chinaz.net/files/default/imgs/2023-11-16/6e397d19e172be9f_s.jpg style_image_url https://scpic3.chinaz.net/files/default/imgs/2023-11-05/d217bbaf821e3a73_s.jpg output_image_size 384# 调整内容图像的大小 content_img_size (output_image_size, output_image_size) # 样式图片大小 style_img_size (256, 256) # 加载并展示图片 content_image load_image(content_image_url, content_img_size) style_image load_image(style_image_url, style_img_size) style_image tf.nn.avg_pool(style_image, ksize[3, 3], strides[1, 1], paddingSAME) show_n([content_image, style_image], [Content image, Style image])加载模型进行风格迁移 # 加载模型 hub_module hub.load(./magenta_arbitrary-image-stylization-v1-256_2) # 风格迁移 outputs hub_module(tf.constant(content_image), tf.constant(style_image)) stylized_image outputs[0] # 展示迁移后的图片 show_n([content_image, style_image, stylized_image], titles[Original content image, Style image, Stylized image])加载本地图片 加载本地图片的话只需要将加载网络图片的代码改成下面的 def load_image(image_url, image_size(256, 256), preserve_aspect_ratioTrue):# 缓存图像文件# image_path tf.keras.utils.get_file(# os.path.basename(image_url)[-128:], image_url)# 加载并转换为float32 numpy数组添加批次维度并规范化为范围[01]。img tf.io.decode_image(tf.io.read_file(image_url),channels3, dtypetf.float32)[tf.newaxis, ...]img crop_center(img)img tf.image.resize(img, image_size, preserve_aspect_ratioTrue)return img下面的效果图是基于一只狗和梵高的星空生成的 完整代码 # import os from matplotlib import gridspec import matplotlib.pylab as plt import numpy as np import tensorflow as tf import tensorflow_hub as hub# 用于将图像裁剪为方形def crop_center(image):# 图片原始形状shape image.shape# 新形状new_shape min(shape[1], shape[2])offset_y max(shape[1]-shape[2], 0) // 2offset_x max(shape[2]-shape[1], 0) // 2# 返回新图片image tf.image.crop_to_bounding_box(image, offset_y, offset_x, new_shape, new_shape)return image# 加载并预处理图片def load_image(image_url, image_size(256, 256), preserve_aspect_ratioTrue):# 缓存图像文件# image_path tf.keras.utils.get_file(# os.path.basename(image_url)[-128:], image_url)# 加载并转换为float32 numpy数组添加批次维度并规范化为范围[01]。img tf.io.decode_image(tf.io.read_file(image_url),channels3, dtypetf.float32)[tf.newaxis, ...]img crop_center(img)img tf.image.resize(img, image_size, preserve_aspect_ratioTrue)return img# 展示图片def show_n(images, titles(,)):n len(images)image_sizes [image.shape[1] for image in images]w (image_sizes[0] * 6) // 320plt.figure(figsize(w * n, w))gs gridspec.GridSpec(1, n, width_ratiosimage_sizes)for i in range(n):plt.subplot(gs[i])plt.imshow(images[i][0], aspectequal)plt.axis(off)plt.title(titles[i] if len(titles) i else )plt.show()content_image_url image/dog.png style_image_url image/fangao.png output_image_size 384# 调整内容图像的大小 content_img_size (output_image_size, output_image_size) # 样式图片大小 style_img_size (256, 256) # 加载图片 content_image load_image(content_image_url, content_img_size) style_image load_image(style_image_url, style_img_size) style_image tf.nn.avg_pool(style_image, ksize[3, 3], strides[1, 1], paddingSAME) # 展示图片 # show_n([content_image, style_image], [Content image, Style image])# 加载模型 hub_module hub.load(./magenta_arbitrary-image-stylization-v1-256_2) # 风格迁移 outputs hub_module(tf.constant(content_image), tf.constant(style_image)) stylized_image outputs[0] # 展示迁移后的图片 show_n([content_image, style_image, stylized_image], titles[Original content image, Style image, Stylized image])
http://www.zqtcl.cn/news/685148/

相关文章:

  • 网站策划机构建筑网站、
  • 邹平做网站的公司标志设计图片大全简单
  • 广东省建设厅官方网站多少钱如何在虚拟机里面做网站
  • 上海免费网站建设模板做网站页面的软件
  • 做折页的网站个人网站有哪些
  • 服装网站建设内容wordpress媒体库只能列表
  • 北京好的做网站的公司东莞专业做淘宝网站
  • 网站结构怎么优化wordpress文章列表添加字段
  • 网站建设框架图长沙官网seo技术厂家
  • 电子商务网站建设主管的策划案html个人网站设计模板
  • 网站首页的head标签内做网站要学的教程
  • 网页设计教学网站江西省建设监督网站
  • 网站建设与发布需要什么提供网站制作公司哪家好
  • 西宁市城市道路建设规划网站探测器 东莞网站建设
  • 旅游村庄网站建设方案小程序制作价格
  • 网站地图制作软件机械加工网免费铺货
  • 网站上线有什么线上活动可以做龙华建网站多少钱
  • 门户网站系统开发建设电脑优化
  • 公司建网站多少钱一个月服务佳的广州网站建设
  • 怎么创建网站建设徐州网站建设要多少钱
  • 微网站功能列表菜市场做建筑设计图库的网站设计
  • 制作网站支付方式定制网站开发哪里好
  • 常州网络网站建设行情软件app网站大全下载
  • 出台网站集约化建设通知彩票网站开发的
  • 怎样创建个人的网站怎么学做网站
  • 小江高端网站建设网站建设中可能升级
  • 网站建设的原则有哪些内容wordpress的底部版权
  • 一个网站建立团队大概要多少钱大连专业网站建设
  • 宁波网站公司相册插件wordpress
  • 科技网站域名大型网站开发团队