Python人工智能之sg2im文字转图像

【人工智能项目】sg2im文字转图像

本次主要对github上的sg2im源码进行执行训练,得到结果。

1.从github上下载源码

!git clone https://github.com/google/sg2im.git

Cloning into 'sg2im'...
remote: Enumerating objects: 85, done.[K
remote: Total 85 (delta 0), reused 0 (delta 0), pack-reused 85[K
Unpacking objects: 100% (85/85), done.

! cp -r sg2im/sg2im sg2im/scripts/

!pip install -r sg2im/requirements.txt

Collecting cloudpickle==0.5.3
Downloading https://files.pythonhosted.org/packages/e7/bf/60ae7ec1e8c6742d2abbb6819c39a48ee796793bcdb7e1d5e41a3e379ddd/cloudpickle-0.5.3-py2.py3-none-any.whl
Requirement already satisfied: cycler==0.10.0 in /usr/local/lib/python3.6/dist-packages (from -r sg2im/requirements.txt (line 2)) (0.10.0)
Collecting Cython==0.28.3
[?25l Downloading https://files.pythonhosted.org/packages/6f/79/d8e2cd00bea8156a995fb284ce7b6677c49eccd2d318f73e201a9ce560dc/Cython-0.28.3-cp36-cp36m-manylinux1_x86_64.whl (3.4MB)
[K |████████████████████████████████| 3.4MB 8.6MB/s
[?25hCollecting dask==0.17.5
[?25l Downloading https://files.pythonhosted.org/packages/91/1a/71be14f468f8f3f94e708afd5662cf75a0ca33a78924ca9f129a9c45c66b/dask-0.17.5-py3-none-any.whl (598kB)
[K |████████████████████████████████| 604kB 30.6MB/s
[?25hCollecting decorator==4.3.0
Downloading https://files.pythonhosted.org/packages/bc/bb/a24838832ba35baf52f32ab1a49b906b5f82fb7c76b2f6a7e35e140bac30/decorator-4.3.0-py2.py3-none-any.whl
Collecting h5py==2.8.0
[?25l Downloading https://files.pythonhosted.org/packages/8e/cb/726134109e7bd71d98d1fcc717ffe051767aac42ede0e7326fd1787e5d64/h5py-2.8.0-cp36-cp36m-manylinux1_x86_64.whl (2.8MB)
[K |████████████████████████████████| 2.8MB 57.5MB/s
[?25hCollecting imageio==2.3.0
[?25l Downloading https://files.pythonhosted.org/packages/a7/1d/33c8686072148b3b0fcc12a2e0857dd8316b8ae20a0fa66c8d6a6d01c05c/imageio-2.3.0-py2.py3-none-any.whl (3.3MB)
[K |████████████████████████████████| 3.3MB 59.0MB/s
[?25hCollecting kiwisolver==1.0.1
[?25l Downloading https://files.pythonhosted.org/packages/69/a7/88719d132b18300b4369fbffa741841cfd36d1e637e1990f27929945b538/kiwisolver-1.0.1-cp36-cp36m-manylinux1_x86_64.whl (949kB)
[K |████████████████████████████████| 952kB 56.0MB/s
[?25hCollecting matplotlib==2.2.2
[?25l Downloading https://files.pythonhosted.org/packages/49/b8/89dbd27f2fb171ce753bb56220d4d4f6dbc5fe32b95d8edc4415782ef07f/matplotlib-2.2.2-cp36-cp36m-manylinux1_x86_64.whl (12.6MB)
[K |████████████████████████████████| 12.6MB 238kB/s
[?25hCollecting networkx==2.1
[?25l Downloading https://files.pythonhosted.org/packages/11/42/f951cc6838a4dff6ce57211c4d7f8444809ccbe2134179950301e5c4c83c/networkx-2.1.zip (1.6MB)
[K |████████████████████████████████| 1.6MB 49.4MB/s
[?25hCollecting numpy==1.14.4
[?25l Downloading https://files.pythonhosted.org/packages/4b/3d/9c0a34ad8544abef864714840fb8954d630b04433f00881bc8fde7b2ab27/numpy-1.14.4-cp36-cp36m-manylinux1_x86_64.whl (12.2MB)
[K |████████████████████████████████| 12.2MB 149kB/s
[?25hCollecting Pillow==5.1.0
[?25l Downloading https://files.pythonhosted.org/packages/5f/4b/8b54ab9d37b93998c81b364557dff9f61972c0f650efa0ceaf470b392740/Pillow-5.1.0-cp36-cp36m-manylinux1_x86_64.whl (2.0MB)
[K |████████████████████████████████| 2.0MB 53.7MB/s
[?25hCollecting pyparsing==2.2.0
[?25l Downloading https://files.pythonhosted.org/packages/6a/8a/718fd7d3458f9fab8e67186b00abdd345b639976bc7fb3ae722e1b026a50/pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
[K |████████████████████████████████| 61kB 9.3MB/s
[?25hCollecting python-dateutil==2.7.3
[?25l Downloading https://files.pythonhosted.org/packages/cf/f5/af2b09c957ace60dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825/python_dateutil-2.7.3-py2.py3-none-any.whl (211kB)
[K |████████████████████████████████| 215kB 49.8MB/s
[?25hCollecting pytz==2018.4
[?25l Downloading https://files.pythonhosted.org/packages/dc/83/15f7833b70d3e067ca91467ca245bae0f6fe56ddc7451aa0dc5606b120f2/pytz-2018.4-py2.py3-none-any.whl (510kB)
[K |████████████████████████████████| 512kB 56.7MB/s
[?25hCollecting PyWavelets==0.5.2
[?25l Downloading https://files.pythonhosted.org/packages/32/c0/3646053c0ce297686da524bc968bff6017151a9089d16c33afe7d330a48b/PyWavelets-0.5.2-cp36-cp36m-manylinux1_x86_64.whl (5.7MB)
[K |████████████████████████████████| 5.7MB 29.6MB/s
[?25hCollecting scikit-image==0.14.0
[?25l Downloading https://files.pythonhosted.org/packages/34/79/cefff573a53ca3fb4c390739d19541b95f371e24d2990aed4cd8837971f0/scikit_image-0.14.0-cp36-cp36m-manylinux1_x86_64.whl (25.3MB)
[K |████████████████████████████████| 25.3MB 115kB/s
[?25hCollecting scipy==1.1.0
[?25l Downloading https://files.pythonhosted.org/packages/a8/0b/f163da98d3a01b3e0ef1cab8dd2123c34aee2bafbb1c5bffa354cc8a1730/scipy-1.1.0-cp36-cp36m-manylinux1_x86_64.whl (31.2MB)
[K |████████████████████████████████| 31.2MB 97kB/s
[?25hCollecting six==1.11.0
Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting toolz==0.9.0
[?25l Downloading https://files.pythonhosted.org/packages/14/d0/a73c15bbeda3d2e7b381a36afb0d9cd770a9f4adc5d1532691013ba881db/toolz-0.9.0.tar.gz (45kB)
[K |████████████████████████████████| 51kB 8.4MB/s
[?25hCollecting torch==0.4.0
[?25l Downloading https://files.pythonhosted.org/packages/69/43/380514bd9663f1bf708abeb359b8b48d3fabb1c8e95bb3427a980a064c57/torch-0.4.0-cp36-cp36m-manylinux1_x86_64.whl (484.0MB)
[K |████████████████████████████████| 484.0MB 33kB/s
[?25hCollecting torchvision==0.2.1
[?25l Downloading https://files.pythonhosted.org/packages/ca/0d/f00b2885711e08bd71242ebe7b96561e6f6d01fdb4b9dcf4d37e2e13c5e1/torchvision-0.2.1-py2.py3-none-any.whl (54kB)
[K |████████████████████████████████| 61kB 9.8MB/s
[?25hRequirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from kiwisolver==1.0.1->-r sg2im/requirements.txt (line 8)) (47.1.1)
Building wheels for collected packages: networkx, toolz
Building wheel for networkx (setup.py) ... [?25l[?25hdone
Created wheel for networkx: filename=networkx-2.1-py2.py3-none-any.whl size=1447765 sha256=4e89cc8350ab7270295c4e879190531eee2b1205e4a7b0c073ed8fe950717a25
Stored in directory: /root/.cache/pip/wheels/44/c0/34/6f98693a554301bdb405f8d65d95bbcd3e50180cbfdd98a94e
Building wheel for toolz (setup.py) ... [?25l[?25hdone
Created wheel for toolz: filename=toolz-0.9.0-cp36-none-any.whl size=53240 sha256=eb0e9434019a90c774ffcbfb077542b8688b43df4895b0c5c57204702dadc064
Stored in directory: /root/.cache/pip/wheels/f4/0c/f6/ce6b2d1aa459ee97cc3c0f82236302bd62d89c86c700219463
Successfully built networkx toolz
[31mERROR: xarray 0.15.1 has requirement numpy>=1.15, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: umap-learn 0.4.3 has requirement numpy>=1.17, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: umap-learn 0.4.3 has requirement scipy>=1.3.1, but you'll have scipy 1.1.0 which is incompatible.[0m
[31mERROR: tifffile 2020.5.30 has requirement numpy>=1.15.1, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: tensorflow 2.2.0 has requirement h5py<2.11.0,>=2.10.0, but you'll have h5py 2.8.0 which is incompatible.[0m
[31mERROR: tensorflow 2.2.0 has requirement numpy<2.0,>=1.16.0, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: tensorflow 2.2.0 has requirement scipy==1.4.1; python_version >= "3", but you'll have scipy 1.1.0 which is incompatible.[0m
[31mERROR: tensorflow 2.2.0 has requirement six>=1.12.0, but you'll have six 1.11.0 which is incompatible.[0m
[31mERROR: tensorflow-probability 0.10.0 has requirement cloudpickle>=1.2.2, but you'll have cloudpickle 0.5.3 which is incompatible.[0m
[31mERROR: tensorflow-hub 0.8.0 has requirement six>=1.12.0, but you'll have six 1.11.0 which is incompatible.[0m
[31mERROR: spacy 2.2.4 has requirement numpy>=1.15.0, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: plotnine 0.6.0 has requirement matplotlib>=3.1.1, but you'll have matplotlib 2.2.2 which is incompatible.[0m
[31mERROR: plotnine 0.6.0 has requirement numpy>=1.16.0, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: plotnine 0.6.0 has requirement scipy>=1.2.0, but you'll have scipy 1.1.0 which is incompatible.[0m
[31mERROR: numba 0.48.0 has requirement numpy>=1.15, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: mizani 0.6.0 has requirement matplotlib>=3.1.1, but you'll have matplotlib 2.2.2 which is incompatible.[0m
[31mERROR: imgaug 0.2.9 has requirement numpy>=1.15.0, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: gym 0.17.2 has requirement cloudpickle<1.4.0,>=1.2.0, but you'll have cloudpickle 0.5.3 which is incompatible.[0m
[31mERROR: google-colab 1.0.0 has requirement six~=1.12.0, but you'll have six 1.11.0 which is incompatible.[0m
[31mERROR: featuretools 0.4.1 has requirement dask>=0.19.4, but you'll have dask 0.17.5 which is incompatible.[0m
[31mERROR: fbprophet 0.6 has requirement python-dateutil>=2.8.0, but you'll have python-dateutil 2.7.3 which is incompatible.[0m
[31mERROR: fastai 1.0.61 has requirement numpy>=1.15, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: fastai 1.0.61 has requirement torch>=1.0.0, but you'll have torch 0.4.0 which is incompatible.[0m
[31mERROR: distributed 1.25.3 has requirement dask>=0.18.0, but you'll have dask 0.17.5 which is incompatible.[0m
[31mERROR: datascience 0.10.6 has requirement folium==0.2.1, but you'll have folium 0.8.3 which is incompatible.[0m
[31mERROR: cvxpy 1.0.31 has requirement numpy>=1.15, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: blis 0.4.1 has requirement numpy>=1.15.0, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: astropy 4.0.1.post1 has requirement numpy>=1.16, but you'll have numpy 1.14.4 which is incompatible.[0m
[31mERROR: albumentations 0.1.12 has requirement imgaug<0.2.7,>=0.2.5, but you'll have imgaug 0.2.9 which is incompatible.[0m
Installing collected packages: cloudpickle, Cython, dask, decorator, six, numpy, h5py, Pillow, imageio, kiwisolver, python-dateutil, pytz, pyparsing, matplotlib, networkx, PyWavelets, scipy, scikit-image, toolz, torch, torchvision
Found existing installation: cloudpickle 1.3.0
Uninstalling cloudpickle-1.3.0:
Successfully uninstalled cloudpickle-1.3.0
Found existing installation: Cython 0.29.19
Uninstalling Cython-0.29.19:
Successfully uninstalled Cython-0.29.19
Found existing installation: dask 2.12.0
Uninstalling dask-2.12.0:
Successfully uninstalled dask-2.12.0
Found existing installation: decorator 4.4.2
Uninstalling decorator-4.4.2:
Successfully uninstalled decorator-4.4.2
Found existing installation: six 1.12.0
Uninstalling six-1.12.0:
Successfully uninstalled six-1.12.0
Found existing installation: numpy 1.18.4
Uninstalling numpy-1.18.4:
Successfully uninstalled numpy-1.18.4
Found existing installation: h5py 2.10.0
Uninstalling h5py-2.10.0:
Successfully uninstalled h5py-2.10.0
Found existing installation: Pillow 7.0.0
Uninstalling Pillow-7.0.0:
Successfully uninstalled Pillow-7.0.0
Found existing installation: imageio 2.4.1
Uninstalling imageio-2.4.1:
Successfully uninstalled imageio-2.4.1
Found existing installation: kiwisolver 1.2.0
Uninstalling kiwisolver-1.2.0:
Successfully uninstalled kiwisolver-1.2.0
Found existing installation: python-dateutil 2.8.1
Uninstalling python-dateutil-2.8.1:
Successfully uninstalled python-dateutil-2.8.1
Found existing installation: pytz 2018.9
Uninstalling pytz-2018.9:
Successfully uninstalled pytz-2018.9
Found existing installation: pyparsing 2.4.7
Uninstalling pyparsing-2.4.7:
Successfully uninstalled pyparsing-2.4.7
Found existing installation: matplotlib 3.2.1
Uninstalling matplotlib-3.2.1:
Successfully uninstalled matplotlib-3.2.1
Found existing installation: networkx 2.4
Uninstalling networkx-2.4:
Successfully uninstalled networkx-2.4
Found existing installation: PyWavelets 1.1.1
Uninstalling PyWavelets-1.1.1:
Successfully uninstalled PyWavelets-1.1.1
Found existing installation: scipy 1.4.1
Uninstalling scipy-1.4.1:
Successfully uninstalled scipy-1.4.1
Found existing installation: scikit-image 0.16.2
Uninstalling scikit-image-0.16.2:
Successfully uninstalled scikit-image-0.16.2
Found existing installation: toolz 0.10.0
Uninstalling toolz-0.10.0:
Successfully uninstalled toolz-0.10.0
Found existing installation: torch 1.5.0+cu101
Uninstalling torch-1.5.0+cu101:
Successfully uninstalled torch-1.5.0+cu101
Found existing installation: torchvision 0.6.0+cu101
Uninstalling torchvision-0.6.0+cu101:
Successfully uninstalled torchvision-0.6.0+cu101
Successfully installed Cython-0.28.3 Pillow-5.1.0 PyWavelets-0.5.2 cloudpickle-0.5.3 dask-0.17.5 decorator-4.3.0 h5py-2.8.0 imageio-2.3.0 kiwisolver-1.0.1 matplotlib-2.2.2 networkx-2.1 numpy-1.14.4 pyparsing-2.2.0 python-dateutil-2.7.3 pytz-2018.4 scikit-image-0.14.0 scipy-1.1.0 six-1.11.0 toolz-0.9.0 torch-0.4.0 torchvision-0.2.1

!bash sg2im/scripts/download_models.sh

--2020-06-05 08:11:22-- https://storage.googleapis.com/sg2im-data/small/coco64.pt
Resolving storage.googleapis.com (storage.googleapis.com)... 173.194.79.128, 2a00:1450:4013:c05::80
Connecting to storage.googleapis.com (storage.googleapis.com)|173.194.79.128|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 119806264 (114M) [application/octet-stream]
Saving to: ‘sg2im-models/coco64.pt'

sg2im-models/coco64 100%[===================>] 114.26M 38.5MB/s in 3.0s

2020-06-05 08:11:25 (38.5 MB/s) - ‘sg2im-models/coco64.pt' saved [119806264/119806264]

--2020-06-05 08:11:25-- https://storage.googleapis.com/sg2im-data/small/vg64.pt
Resolving storage.googleapis.com (storage.googleapis.com)... 108.177.119.128, 2a00:1450:4013:c00::80
Connecting to storage.googleapis.com (storage.googleapis.com)|108.177.119.128|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 119873465 (114M) [application/octet-stream]
Saving to: ‘sg2im-models/vg64.pt'

sg2im-models/vg64.p 100%[===================>] 114.32M 44.0MB/s in 2.6s

2020-06-05 08:11:29 (44.0 MB/s) - ‘sg2im-models/vg64.pt' saved [119873465/119873465]

--2020-06-05 08:11:29-- https://storage.googleapis.com/sg2im-data/small/vg128.pt
Resolving storage.googleapis.com (storage.googleapis.com)... 74.125.128.128, 2a00:1450:4013:c02::80
Connecting to storage.googleapis.com (storage.googleapis.com)|74.125.128.128|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 129319241 (123M) [application/octet-stream]
Saving to: ‘sg2im-models/vg128.pt'

sg2im-models/vg128. 100%[===================>] 123.33M 54.2MB/s in 2.3s

2020-06-05 08:11:32 (54.2 MB/s) - ‘sg2im-models/vg128.pt' saved [129319241/129319241]

2.训练与结果展示

!python3 sg2im/scripts/run_model.py --checkpoint sg2im-models/vg128.pt --scene_graphs sg2im/scene_graphs/figure_6_sheep.json --output_dir outputs

import matplotlib.pyplot as plt
import cv2
%matplotlib inline

img0 = cv2.imread("outputs/img000000.png")
img1 = cv2.imread("outputs/img000001.png")
img2 = cv2.imread("outputs/img000002.png")
img3 = cv2.imread("outputs/img000003.png")
img4 = cv2.imread("outputs/img000004.png")
img5 = cv2.imread("outputs/img000005.png")
img6 = cv2.imread("outputs/img000006.png")

plt.figure()
plt.subplot(3,3,1)
plt.imshow(img0)
plt.subplot(3,3,2)
plt.imshow(img1)
plt.subplot(3,3,3)
plt.imshow(img2)
plt.subplot(3,3,4)
plt.imshow(img3)
plt.subplot(3,3,5)
plt.imshow(img4)
plt.subplot(3,3,6)
plt.imshow(img5)
plt.subplot(3,3,7)
plt.imshow(img6)

<matplotlib.image.AxesImage at 0x7fa2bdfb36d8>

!python3 sg2im/scripts/run_model.py --checkpoint sg2im-models/vg128.pt --scene_graphs sg2im/scene_graphs/figure_6_street.json --output_dir outputs

import matplotlib.pyplot as plt
import cv2
%matplotlib inline

img0 = cv2.imread("outputs/img000000.png")
img1 = cv2.imread("outputs/img000001.png")
img2 = cv2.imread("outputs/img000002.png")
img3 = cv2.imread("outputs/img000003.png")
img4 = cv2.imread("outputs/img000004.png")
img5 = cv2.imread("outputs/img000005.png")
img6 = cv2.imread("outputs/img000006.png")

plt.figure()
plt.subplot(3,3,1)
plt.imshow(img0)
plt.subplot(3,3,2)
plt.imshow(img1)
plt.subplot(3,3,3)
plt.imshow(img2)
plt.subplot(3,3,4)
plt.imshow(img3)
plt.subplot(3,3,5)
plt.imshow(img4)
plt.subplot(3,3,6)
plt.imshow(img5)
plt.subplot(3,3,7)
plt.imshow(img6)

<matplotlib.image.AxesImage at 0x7fa2be14d1d0>

!python3 sg2im/scripts/run_model.py --checkpoint sg2im-models/vg128.pt --scene_graphs sg2im/scene_graphs/figure_5_vg.json --output_dir outputs

import matplotlib.pyplot as plt
import cv2
%matplotlib inline

img0 = cv2.imread("outputs/img000000.png")
img1 = cv2.imread("outputs/img000001.png")
img2 = cv2.imread("outputs/img000002.png")
img3 = cv2.imread("outputs/img000003.png")
img4 = cv2.imread("outputs/img000004.png")
img5 = cv2.imread("outputs/img000005.png")
img6 = cv2.imread("outputs/img000006.png")
img7 = cv2.imread("outputs/img000007.png")

plt.figure()
plt.subplot(3,3,1)
plt.imshow(img0)
plt.subplot(3,3,2)
plt.imshow(img1)
plt.subplot(3,3,3)
plt.imshow(img2)
plt.subplot(3,3,4)
plt.imshow(img3)
plt.subplot(3,3,5)
plt.imshow(img4)
plt.subplot(3,3,6)
plt.imshow(img5)
plt.subplot(3,3,7)
plt.imshow(img6)
plt.subplot(3,3,8)
plt.imshow(img7)

<matplotlib.image.AxesImage at 0x7fa2bdd710f0>

小结

瓷们 ,点赞收藏评论走起来!

到此这篇关于Python人工智能之sg2im文字转图像的文章就介绍到这了,更多相关Python 人工智能内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Python人工智能之路 之PyAudio 实现录音 自动化交互实现问答

    Python 很强大其原因就是因为它庞大的三方库 , 资源是非常的丰富 , 当然也不会缺少关于音频的库 关于音频, PyAudio 这个库, 可以实现开启麦克风录音, 可以播放音频文件等等,此刻我们不去了解其他的功能,只了解一下它如何实现录音的 首先要先 pip 一个 PyAudio pip install pyaudio 一.PyAudio 实现麦克风录音 然后建立一个py文件,复制如下代码 import pyaudio import wave CHUNK = 1024 FORMAT = py

  • Python人工智能之路 jieba gensim 最好别分家之最简单的相似度实现

    简单的问答已经实现了,那么问题也跟着出现了,我不能确定问题一定是"你叫什么名字",也有可能是"你是谁","你叫啥"之类的,这就引出了人工智能中的另一项技术: 自然语言处理(NLP) : 大概意思就是 让计算机明白一句话要表达的意思,NLP就相当于计算机在思考你说的话,让计算机知道"你是谁","你叫啥","你叫什么名字"是一个意思 这就要做 : 语义相似度 接下来我们用Python大法来实

  • python实现人工智能Ai抠图功能

    自己是个PS小白,没办法只能通过技术来证明自己. 话不多说,直接上代码 from removebg import RemoveBg import requests import os if __name__ == '__main__': path = '%s\picture'%os.getcwd() ispath = os.path.exists(path) if not ispath: os.mkdir(path) response = requests.post( 'https://api.

  • Python人工智能之sg2im文字转图像

    [人工智能项目]sg2im文字转图像 本次主要对github上的sg2im源码进行执行训练,得到结果. 1.从github上下载源码 !git clone https://github.com/google/sg2im.git Cloning into 'sg2im'... remote: Enumerating objects: 85, done.[K remote: Total 85 (delta 0), reused 0 (delta 0), pack-reused 85[K Unpack

  • python简单实现图片文字分割

    本文实例为大家分享了python简单实现图片文字分割的具体代码,供大家参考,具体内容如下 原图: 图片预处理:图片二值化以及图片降噪处理. # 图片二值化 def binarization(img,threshold): #图片二值化操作 width,height=img.size im_new = img.copy() for i in range(width): for j in range(height): a = img.getpixel((i, j)) aa = 0.30 * a[0]

  • python中opencv实现文字分割的实践

    图片文字分割的时候,常用的方法有两种.一种是投影法,适用于排版工整,字间距行间距比较宽裕的图像:还有一种是用OpenCV的轮廓检测,适用于文字不规则排列的图像. 投影法 对文字图片作横向和纵向投影,即通过统计出每一行像素个数,和每一列像素个数,来分割文字. 分别在水平和垂直方向对预处理(二值化)的图像某一种像素进行统计,对于二值化图像非黑即白,我们通过对其中的白点或者黑点进行统计,根据统计结果就可以判断出每一行的上下边界以及每一列的左右边界,从而实现分割的目的. 算法步骤: 使用水平投影和垂直投

  • Python人工智能深度学习CNN

    目录 1.CNN概述 2.卷积层 3.池化层 4.全连层 1.CNN概述 CNN的整体思想,就是对图片进行下采样,让一个函数只学一个图的一部分,这样便得到少但是更有效的特征,最后通过全连接神经网络对结果进行输出. 整体架构如下: 输入图片 →卷积:得到特征图(激活图) →ReLU:去除负值 →池化:缩小数据量同时保留最有效特征 (以上步骤可多次进行) →输入全连接神经网络 2.卷积层 CNN-Convolution 卷积核(或者被称为kernel, filter, neuron)是要被学出来的,

  • Python人工智能深度学习模型训练经验总结

    目录 一.假如训练集表现不好 1.尝试新的激活函数 2.自适应学习率 ①Adagrad ②RMSProp ③ Momentum ④Adam 二.在测试集上效果不好 1.提前停止 2.正则化 3.Dropout 一.假如训练集表现不好 1.尝试新的激活函数 ReLU:Rectified Linear Unit 图像如下图所示:当z<0时,a = 0, 当z>0时,a = z,也就是说这个激活函数是对输入进行线性转换.使用这个激活函数,由于有0的存在,计算之后会删除掉一些神经元,使得神经网络变窄.

  • python人工智能tensorflow常用激活函数Activation Functions

    目录 常见的激活函数种类及其图像 1 sigmoid(logsig)函数 2 tanh函数 3 relu函数 4 softplus函数 tensorflow中损失函数的表达 1 sigmoid(logsig)函数 2 tanh函数 3 relu函数 4 softplus函数 激活函数在机器学习中常常用在神经网络隐含层节点与神经网络的输出层节点上,激活函数的作用是赋予神经网络更多的非线性因素,如果不用激励函数,输出都是输入的线性组合,这种情况与最原始的感知机相当,网络的逼近能力相当有限.如果能够引

  • python人工智能tensorflow函数tf.nn.dropout使用方法

    目录 前言 tf.nn.dropout函数介绍 例子 代码 keep_prob = 0.5 keep_prob = 1 前言 神经网络在设置的神经网络足够复杂的情况下,可以无限逼近一段非线性连续函数,但是如果神经网络设置的足够复杂,将会导致过拟合(overfitting)的出现,就好像下图这样. 看到这个蓝色曲线,我就知道: 很明显蓝色曲线是overfitting的结果,尽管它很好的拟合了每一个点的位置,但是曲线是歪歪曲曲扭扭捏捏的,这个的曲线不具有良好的鲁棒性,在实际工程实验中,我们更希望得到

  • python人工智能tensorflow构建卷积神经网络CNN

    目录 简介 隐含层介绍 1.卷积层 2.池化层 3.全连接层 具体实现代码 卷积层.池化层与全连接层实现代码 全部代码 学习神经网络已经有一段时间,从普通的BP神经网络到LSTM长短期记忆网络都有一定的了解,但是从未系统的把整个神经网络的结构记录下来,我相信这些小记录可以帮助我更加深刻的理解神经网络. 简介 卷积神经网络(Convolutional Neural Networks, CNN)是一类包含卷积计算且具有深度结构的前馈神经网络(Feedforward Neural Networks),

  • python人工智能tensorflow常见损失函数LOSS汇总

    目录 前言 运算公式 1 均方差函数 2 交叉熵函数 tensorflow中损失函数的表达 1 均方差函数 2 交叉熵函数 例子 1 均方差函数 2 交叉熵函数 前言 损失函数在机器学习中用于表示预测值与真实值之间的差距.一般而言,大多数机器学习模型都会通过一定的优化器来减小损失函数从而达到优化预测机器学习模型参数的目的.哦豁,损失函数这么必要,那都存在什么损失函数呢? 一般常用的损失函数是均方差函数和交叉熵函数. 运算公式 1 均方差函数 均方差函数主要用于评估回归模型的使用效果,其概念相对简

随机推荐