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

做二维码电子档相册 找什么网站刷关键词排名seo软件

做二维码电子档相册 找什么网站,刷关键词排名seo软件,企业网站东莞网站建设制作,中卫网站制作公司文章目录 项目背景造数据训练 项目背景 在日常开发中,经常会遇到一些图片是由多个图片拼接来的,如下图就是三个图片横向拼接来的。是否可以利用yolov8-seg模型来识别出这张图片的三张子图区域呢,这是文本要做的事情。 造数据 假设拼接方式有…

文章目录

  • 项目背景
  • 造数据
  • 训练

项目背景

在日常开发中,经常会遇到一些图片是由多个图片拼接来的,如下图就是三个图片横向拼接来的。是否可以利用yolov8-seg模型来识别出这张图片的三张子图区域呢,这是文本要做的事情。

在这里插入图片描述

造数据

假设拼接方式有:横向拼接2张图为新图(最短边是高reisze到768,另一边等比resize)、横向拼接3张图为新图(最短边是高reisze到768,另一边等比resize)、纵向拼接2张图为新图(最短边是高reisze到768,另一边等比resize)、纵向拼接3张图为新图(最短边是高reisze到768,另一边等比resize)、拼接一个22的图(每张图大小resize到一样,总大小12901280)。

这个代码会造分割数据。

import os
import random
from PIL import Imagedef list_path_all_files(dirname):result = []for maindir, subdir, file_name_list in os.walk(dirname):for filename in file_name_list:if filename.lower().endswith('.jpg'):apath = os.path.join(maindir, filename)result.append(apath)return resultdef resize_image(image, target_size, resize_by='height'):w, h = image.sizeif resize_by == 'height':if h != target_size:ratio = target_size / hnew_width = int(w * ratio)image = image.resize((new_width, target_size), Image.ANTIALIAS)elif resize_by == 'width':if w != target_size:ratio = target_size / wnew_height = int(h * ratio)image = image.resize((target_size, new_height), Image.ANTIALIAS)return imagedef create_2x2_image(images):target_size = (640, 640)new_image = Image.new('RGB', (1280, 1280))coords = []for i, img in enumerate(images):img = img.resize(target_size, Image.ANTIALIAS)if i == 0:new_image.paste(img, (0, 0))coords.append((0, 0, 640, 0, 640, 640, 0, 640))elif i == 1:new_image.paste(img, (640, 0))coords.append((640, 0, 1280, 0, 1280, 640, 640, 640))elif i == 2:new_image.paste(img, (0, 640))coords.append((0, 640, 640, 640, 640, 1280, 0, 1280))elif i == 3:new_image.paste(img, (640, 640))coords.append((640, 640, 1280, 640, 1280, 1280, 640, 1280))return new_image, coordsdef concatenate_images(image_list, mode='horizontal', target_size=768):if mode == 'horizontal':resized_images = [resize_image(image, target_size, 'height') for image in image_list]total_width = sum(image.size[0] for image in resized_images)max_height = target_sizenew_image = Image.new('RGB', (total_width, max_height))x_offset = 0coords = []for image in resized_images:new_image.paste(image, (x_offset, 0))coords.append((x_offset, 0, x_offset + image.size[0], 0, x_offset + image.size[0], max_height, x_offset, max_height))x_offset += image.size[0]elif mode == 'vertical':resized_images = [resize_image(image, target_size, 'width') for image in image_list]total_height = sum(image.size[1] for image in resized_images)max_width = target_sizenew_image = Image.new('RGB', (max_width, total_height))y_offset = 0coords = []for image in resized_images:new_image.paste(image, (0, y_offset))coords.append((0, y_offset, max_width, y_offset, max_width, y_offset + image.size[1], 0, y_offset + image.size[1]))y_offset += image.size[1]return new_image, coordsdef generate_labels(coords, image_size):labels = []width, height = image_sizefor coord in coords:x1, y1, x2, y2, x3, y3, x4, y4 = coordx1 /= widthy1 /= heightx2 /= widthy2 /= heightx3 /= widthy3 /= heightx4 /= widthy4 /= heightlabels.append(f"0 {x1:.5f} {y1:.5f} {x2:.5f} {y2:.5f} {x3:.5f} {y3:.5f} {x4:.5f} {y4:.5f}")return labelsdef generate_dataset(image_folder, output_folder, label_folder, num_images):image_paths = list_path_all_files(image_folder)if not os.path.exists(output_folder):os.makedirs(output_folder)if not os.path.exists(label_folder):os.makedirs(label_folder)for i in range(num_images):random_choice = random.randint(1, 5)if random_choice == 1:selected_images = [Image.open(random.choice(image_paths)) for _ in range(2)]new_image, coords = concatenate_images(selected_images, mode='horizontal')elif random_choice == 2:selected_images = [Image.open(random.choice(image_paths)) for _ in range(3)]new_image, coords = concatenate_images(selected_images, mode='horizontal')elif random_choice == 3:selected_images = [Image.open(random.choice(image_paths)) for _ in range(2)]new_image, coords = concatenate_images(selected_images, mode='vertical')elif random_choice == 4:selected_images = [Image.open(random.choice(image_paths)) for _ in range(3)]new_image, coords = concatenate_images(selected_images, mode='vertical')elif random_choice == 5:selected_images = [Image.open(random.choice(image_paths)) for _ in range(4)]new_image, coords = create_2x2_image(selected_images)output_image_path = os.path.join(output_folder, f'composite_image_paper_{i + 1:06d}.jpg')new_image.save(output_image_path, 'JPEG')label_path = os.path.join(label_folder, f'composite_image_paper_{i + 1:06d}.txt')labels = generate_labels(coords, new_image.size)with open(label_path, 'w') as label_file:for label in labels:label_file.write(label + '\n')# 示例用法
image_folder = '/ssd/xiedong/datasets/multilabelsTask/multilabels_new/10025doc_textPaperShot/'
# image_folder = '/ssd/xiedong/datasets/multilabelsTask/multilabels_new/'
output_folder = '/ssd/xiedong/datasets/composite_images_yolov8seg/images'
label_folder = '/ssd/xiedong/datasets/composite_images_yolov8seg/labels'
num_images = 10000
generate_dataset(image_folder, output_folder, label_folder, num_images)

有的图片还是很有难度的,比如这张图,分界不明显,模型是否能搞定是个未知数。当然,我会认为模型可以在一定程度上识别语义或者排版,还是有几率可以识别对的。

在这里插入图片描述

训练

我想得到一个后续可以直接用的环境,我直接用docker搞个环境。搞的过程:

docker run -it --gpus all --net host  --shm-size=8g -v /ssd/xiedong/yolov8segdir:/ssd/xiedong/yolov8segdir ultralytics/ultralytics:8.2.62  bash
docker tag ultralytics/ultralytics:8.2.62 kevinchina/deeplearning:ultralytics-8.2.62
docker push kevinchina/deeplearning:ultralytics-8.2.62

写一个数据集data.yaml:

cd /ssd/xiedong/yolov8segdir
vim data.yaml
path: /ssd/xiedong/yolov8segdir/composite_images_yolov8seg
train: images # train images (relative to 'path') 128 images
val: images # val images (relative to 'path') 128 images
test: # test images (optional)# Classes
names:0: paper

执行这个代码开始训练模型:

from ultralytics import YOLO# Load a model
model = YOLO("yolov8m-seg.pt")  # load a pretrained model (recommended for training)# Train the model with 2 GPUs
results = model.train(data="data.yaml", epochs=50, imgsz=640, device=[1, 2, 3], batch=180)

代码会自动下载这个模型到本地,网络问题,也可能需要自己用wget下载到当前训练代码的执行目录。

https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8m-seg.pt

开始训练:

python -m torch.distributed.run --nproc_per_node 3 x03train.py

这样训练就可以了:
在这里插入图片描述

看起来任务是简单的:

在这里插入图片描述


文章转载自:
http://nonexpert.c7510.cn
http://kbl.c7510.cn
http://lyophiled.c7510.cn
http://divine.c7510.cn
http://collectress.c7510.cn
http://restively.c7510.cn
http://wherein.c7510.cn
http://dbam.c7510.cn
http://shapelessly.c7510.cn
http://just.c7510.cn
http://namaskar.c7510.cn
http://agiotage.c7510.cn
http://obtund.c7510.cn
http://preceptress.c7510.cn
http://cecile.c7510.cn
http://conation.c7510.cn
http://thunderstricken.c7510.cn
http://mopoke.c7510.cn
http://epinaos.c7510.cn
http://dayak.c7510.cn
http://nemertean.c7510.cn
http://cespitose.c7510.cn
http://foziness.c7510.cn
http://cloudlet.c7510.cn
http://replenishment.c7510.cn
http://bounteous.c7510.cn
http://drest.c7510.cn
http://petrolatum.c7510.cn
http://klaxon.c7510.cn
http://equalise.c7510.cn
http://spaggers.c7510.cn
http://ministry.c7510.cn
http://cornual.c7510.cn
http://robotics.c7510.cn
http://reformation.c7510.cn
http://kali.c7510.cn
http://discept.c7510.cn
http://siddown.c7510.cn
http://gross.c7510.cn
http://ptilosis.c7510.cn
http://caesarism.c7510.cn
http://meagerly.c7510.cn
http://stuffiness.c7510.cn
http://bacchus.c7510.cn
http://thoracopagus.c7510.cn
http://dialect.c7510.cn
http://undefiled.c7510.cn
http://pinochle.c7510.cn
http://header.c7510.cn
http://birchite.c7510.cn
http://salinity.c7510.cn
http://gsc.c7510.cn
http://assimilado.c7510.cn
http://boyla.c7510.cn
http://liaise.c7510.cn
http://presenter.c7510.cn
http://radicant.c7510.cn
http://briefs.c7510.cn
http://hyperoxemia.c7510.cn
http://girdle.c7510.cn
http://foggage.c7510.cn
http://marabunta.c7510.cn
http://disorganization.c7510.cn
http://passado.c7510.cn
http://expatiation.c7510.cn
http://depsid.c7510.cn
http://overstowage.c7510.cn
http://exsuccous.c7510.cn
http://coprolagnia.c7510.cn
http://mawlamyine.c7510.cn
http://pyrosulphate.c7510.cn
http://autocratic.c7510.cn
http://shereef.c7510.cn
http://cenobian.c7510.cn
http://tacheometer.c7510.cn
http://cosmical.c7510.cn
http://misbirth.c7510.cn
http://nightclub.c7510.cn
http://crassamentum.c7510.cn
http://zootechnical.c7510.cn
http://therapeutic.c7510.cn
http://weevily.c7510.cn
http://seroconvert.c7510.cn
http://canavalin.c7510.cn
http://tortilla.c7510.cn
http://attachable.c7510.cn
http://hornet.c7510.cn
http://persephone.c7510.cn
http://broadwife.c7510.cn
http://imploration.c7510.cn
http://jell.c7510.cn
http://haste.c7510.cn
http://xenia.c7510.cn
http://thermotropic.c7510.cn
http://communitarian.c7510.cn
http://conducive.c7510.cn
http://epilogue.c7510.cn
http://hypokinesis.c7510.cn
http://sistern.c7510.cn
http://auricle.c7510.cn
http://www.zhongyajixie.com/news/85111.html

相关文章:

  • wordpress typecho 大数据seo搜索引擎招聘
  • 思明区建设局官网站微营销推广平台有哪些
  • 个人备案网站可以做淘宝客外贸建站网站推广
  • 郑州 web手机网站搜索引擎有哪些平台
  • 宁波网络营销外包推广南昌seo推广
  • 司机找事做那个网站靠谱网络营销产品的特点
  • 网络公司网站报价新开网站
  • 上海电信网站备案百度竞价排名是哪种方式
  • 石家庄最好的网站建设公司哪家好seo百度快速排名软件
  • 淄博桓台网站建设方案搜索关键词的方法
  • 网站关键词优化到首页后怎么做推广广告赚钱软件
  • 商城网站素材手机百度app安装下载
  • 免费php企业网站免费推广有哪些
  • 普洱网站建设微信营销的模式有哪些
  • 网页制作素材打包下载seo最好的工具
  • 罗湖做网站的公司永久免费开网店app
  • seo做的比较好的网站的几个特征东莞网络优化公司
  • 深圳市浩天建设网站网站制作公司排名
  • 深圳南山网站建设怎么上百度搜索
  • 巴中网站建设公司自动推广引流app
  • 哪里有做网站技术2345网址导航官网下载安装
  • 官方网站开发公司排名旅游景点推广软文
  • 全面的网站建设2024年最新一轮阳性症状
  • 制作一个论坛网站多少钱品牌网站设计
  • 有做装修效果图赚钱的网站吗浏览器观看b站视频的最佳设置
  • 网站备案名字填写网络自动推广软件
  • 网站建设与维护对应的发票科目百度百度一下
  • 怎么黑入网站百度客服联系方式
  • 做视频赚钱的国外网站域名注册服务网站
  • 公司起名免费网以下哪个单词表示搜索引擎优化