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

北京地铁建设的网站网站建设费用

北京地铁建设的网站,网站建设费用,订单网站怎么做,wordpress4.9标签404一、简介和环境准备 knn一般指邻近算法。 邻近算法,或者说K最邻近(KNN,K-NearestNeighbor)分类算法是数据挖掘分类技术中最简单的方法之一。而lmknn是局部均值k最近邻分类算法。 本次实验环境需要用的是Google Colab和Google Dr…

一、简介和环境准备

knn一般指邻近算法。 邻近算法,或者说K最邻近(KNN,K-NearestNeighbor)分类算法是数据挖掘分类技术中最简单的方法之一。而lmknn是局部均值k最近邻分类算法。

本次实验环境需要用的是Google Colab和Google Drive(云盘),文件后缀是.ipynb可以直接用。首先登录谷歌云盘(网页),再打卡ipynb文件就可以跳转到谷歌colab了。再按以下点击顺序将colab和云盘链接。

from google.colab import drive
drive.mount('/content/drive')

 准备的数据是一些分类好的手写汉字图(实验来源在结尾)

引入库

from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from imutils import paths
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import glob
import argparse
import imutils
import cv2
import os
# import sys
# np.set_printoptions(threshold=sys.maxsize)

二、数据预处理和算法简介

2.1预处理

注意路径的修改。这一步处理所有图片数据,存到xy的train和test。

x_train = []
y_train = []
x_test = []
y_test = []for i in os.listdir('./drive/MyDrive/Chinese-HCR-master/TA_dataset/train'):for filename in glob.glob('drive/MyDrive/Chinese-HCR-master/TA_dataset/train/'+str(i)+'/*.png'):im = cv2.imread(filename, 0)        im = cv2.resize(im, (128, 128)) # resize to 128 * 128 pixel sizeblur = cv2.GaussianBlur(im, (5,5), 0) # using Gaussian blurret, th = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)x_train.append(th)y_train.append(i) # append classfor i in os.listdir('./drive/MyDrive/Chinese-HCR-master/TA_dataset/test'):for filename in glob.glob('drive/MyDrive/Chinese-HCR-master/TA_dataset/test/'+str(i)+'/*.png'):im = cv2.imread(filename, 0)        im = cv2.resize(im, (128, 128)) # resize to 128 * 128 pixel sizeblur = cv2.GaussianBlur(im, (5,5), 0) # using Gaussian blurret, th = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)x_test.append(th)y_test.append(i) # append class
x_train = np.array(x_train) / 255
x_test = np.array(x_test) / 255
y_train = np.array(y_train)
# x_train = np.array(x_train)
# x_test = np.array(x_test)

可以打印看一下

plt.imshow(x_train[0])
plt.show()

plt.imshow(x_test[0], 'gray')
plt.show()

 2.2算法代码

1.KNN

这里不像上一章分析源码,只调用

from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score
neigh = KNeighborsClassifier(n_neighbors=3)
xtrain = np.reshape(x_train, (x_train.shape[0], x_train.shape[1] * x_train.shape[1]))
xtest = np.reshape(x_test, (x_test.shape[0], x_test.shape[1] * x_test.shape[1]))
prediction = neigh.fit(xtrain, y_train).predict(xtrain)
prediction
print(accuracy_score(y_train,prediction))

0.7969348659003831

2.基于HOG特征提取的KNN

from skimage.feature import hog
features = np.array(xtrain, 'int64')
labels = y_train
list_hog_fd = []
for feature in features:fd = hog(feature.reshape((128, 128)), orientations=8, pixels_per_cell=(64, 64), cells_per_block=(1, 1), )list_hog_fd.append(fd)
hog_features = np.array(list_hog_fd)
hog_features

array([[0.52801754, 0. , 0.52801754, ..., 0. , 0.5 , 0. ], [0.35309579, 0. , 0.54016151, ..., 0. , 0.5 , 0. ], [0.5 , 0. , 0.5 , ..., 0. , 0.5 , 0. ], ..., [0.5035908 , 0. , 0.59211517, ..., 0. , 0.5 , 0. ], [0.51920317, 0. , 0.51920317, ..., 0. , 0.5 , 0. ], [0.55221191, 0. , 0.55221191, ..., 0. , 0.5 , 0. ]])

(注:如果没运行1的knn 要先跑下面的)

neigh = KNeighborsClassifier(n_neighbors=3)
xtrain = np.reshape(x_train, (x_train.shape[0], x_train.shape[1] * x_train.shape[1]))
xtest = np.reshape(x_test, (x_test.shape[0], x_test.shape[1] * x_test.shape[1]))
prediction = neigh.fit(hog_features, labels).predict(hog_features)
prediction
print(accuracy_score(labels,prediction))

0.6360153256704981

3.带骨架的KNN

from skimage.morphology import skeletonize
from skimage import data
import matplotlib.pyplot as plt
from skimage.util import invert# Invert the horse image
image = invert(x_train[0])# perform skeletonization
skeleton = skeletonize(image)# display results
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 4),sharex=True, sharey=True)ax = axes.ravel()ax[0].imshow(image, cmap=plt.cm.gray)
ax[0].axis('off')
ax[0].set_title('original', fontsize=20)ax[1].imshow(skeleton, cmap=plt.cm.gray)
ax[1].axis('off')
ax[1].set_title('skeleton', fontsize=20)fig.tight_layout()
plt.show()

from sklearn.neighbors import KNeighborsClassifier
neigh = KNeighborsClassifier(n_neighbors=3)
xtrain = np.reshape(x_train, (x_train.shape[0], x_train.shape[1] * x_train.shape[1]))
xtest = np.reshape(x_test, (x_test.shape[0], x_test.shape[1] * x_test.shape[1]))
from sklearn.metrics import accuracy_score
prediction = neigh.fit(xtrain, y_train).predict(xtrain)
prediction
print(accuracy_score(y_train,prediction))

0.7969348659003831

4.拓展--Otsu方法概述

import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
img = cv.imread('drive/MyDrive/Chinese-HCR-master/TA_dataset/train/亮/37162.png',0)
img = cv.medianBlur(img,5)
ret,th1 = cv.threshold(img,127,255,cv.THRESH_BINARY)
th2 = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_MEAN_C,\cv.THRESH_BINARY,11,2)
th3 = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,\cv.THRESH_BINARY,11,2)
titles = ['Original Image', 'Global Thresholding (v = 127)','Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding']
images = [img, th1, th2, th3]
for i in range(4):plt.subplot(2,2,i+1),plt.imshow(images[i],'gray')plt.title(titles[i])plt.xticks([]),plt.yticks([])
plt.show()

import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
img = cv.imread('drive/MyDrive/Chinese-HCR-master/TA_dataset/train/亮/37162.png',0)
# global thresholding
ret1,th1 = cv.threshold(img,127,255,cv.THRESH_BINARY)
# Otsu's thresholding
ret2,th2 = cv.threshold(img,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
# Otsu's thresholding after Gaussian filtering
blur = cv.GaussianBlur(img,(5,5),0)
ret3,th3 = cv.threshold(blur,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
# plot all the images and their histograms
images = [img, 0, th1,img, 0, th2,blur, 0, th3]
titles = ['Original Noisy Image','Histogram','Global Thresholding (v=127)','Original Noisy Image','Histogram',"Otsu's Thresholding",'Gaussian filtered Image','Histogram',"Otsu's Thresholding"]
for i in range(3):plt.subplot(3,3,i*3+1),plt.imshow(images[i*3],'gray')plt.title(titles[i*3]), plt.xticks([]), plt.yticks([])plt.subplot(3,3,i*3+2),plt.hist(images[i*3].ravel(),256)plt.title(titles[i*3+1]), plt.xticks([]), plt.yticks([])plt.subplot(3,3,i*3+3),plt.imshow(images[i*3+2],'gray')plt.title(titles[i*3+2]), plt.xticks([]), plt.yticks([])
plt.show()


来源:GitHub - NovitaGuok/Chinese-HCR: A Chinese Character Recognition system using KNN, LMPNN, and MVMCNN


文章转载自:
http://guadalcanal.c7624.cn
http://glarney.c7624.cn
http://unbribable.c7624.cn
http://canikin.c7624.cn
http://cleo.c7624.cn
http://signalman.c7624.cn
http://marcionism.c7624.cn
http://larynx.c7624.cn
http://destructional.c7624.cn
http://spectrophotofluorometer.c7624.cn
http://causationist.c7624.cn
http://ui.c7624.cn
http://hemoblast.c7624.cn
http://replicable.c7624.cn
http://jewess.c7624.cn
http://nifty.c7624.cn
http://australian.c7624.cn
http://alexandrite.c7624.cn
http://elucidator.c7624.cn
http://myope.c7624.cn
http://acnode.c7624.cn
http://troubleshooter.c7624.cn
http://here.c7624.cn
http://enostosis.c7624.cn
http://dejectile.c7624.cn
http://sava.c7624.cn
http://upload.c7624.cn
http://duteous.c7624.cn
http://mandarine.c7624.cn
http://litigate.c7624.cn
http://fixt.c7624.cn
http://magnesia.c7624.cn
http://impressiveness.c7624.cn
http://vorticose.c7624.cn
http://noncommissioned.c7624.cn
http://pyramid.c7624.cn
http://iridocyclitis.c7624.cn
http://salverform.c7624.cn
http://scrutinous.c7624.cn
http://ventless.c7624.cn
http://cannibalistic.c7624.cn
http://nasaiism.c7624.cn
http://riquewihr.c7624.cn
http://brushup.c7624.cn
http://universalise.c7624.cn
http://singletree.c7624.cn
http://leafed.c7624.cn
http://overdrove.c7624.cn
http://immovability.c7624.cn
http://lacrymal.c7624.cn
http://nomological.c7624.cn
http://badger.c7624.cn
http://valorisation.c7624.cn
http://bacterioscopy.c7624.cn
http://gaston.c7624.cn
http://timbre.c7624.cn
http://approved.c7624.cn
http://grisaille.c7624.cn
http://rebab.c7624.cn
http://tania.c7624.cn
http://outyell.c7624.cn
http://handwheel.c7624.cn
http://frankfurter.c7624.cn
http://pursiness.c7624.cn
http://dichloride.c7624.cn
http://remanufacture.c7624.cn
http://laminative.c7624.cn
http://depasture.c7624.cn
http://yorks.c7624.cn
http://subopposite.c7624.cn
http://witch.c7624.cn
http://mukhtar.c7624.cn
http://inez.c7624.cn
http://declared.c7624.cn
http://prelacy.c7624.cn
http://vina.c7624.cn
http://hobbyhorse.c7624.cn
http://amidogroup.c7624.cn
http://monica.c7624.cn
http://rationing.c7624.cn
http://subapostolic.c7624.cn
http://sportscast.c7624.cn
http://gagger.c7624.cn
http://aphyllous.c7624.cn
http://inquisitress.c7624.cn
http://duodenitis.c7624.cn
http://tabulator.c7624.cn
http://hearty.c7624.cn
http://intellective.c7624.cn
http://sinanthropus.c7624.cn
http://dah.c7624.cn
http://privileged.c7624.cn
http://bug.c7624.cn
http://bestrew.c7624.cn
http://dumbhead.c7624.cn
http://noninvolvement.c7624.cn
http://secrecy.c7624.cn
http://fraise.c7624.cn
http://craggedness.c7624.cn
http://kumbaloi.c7624.cn
http://www.zhongyajixie.com/news/88962.html

相关文章:

  • 有什么做服装的网站吗百度知道个人中心
  • 宜昌十堰网站建设哪家好江苏seo平台
  • 大疆网站建设百度推广费2800元每年都有吗
  • dede网站怎么备份中国疫情最新数据
  • 沈阳个人做网站厦门seo关键词优化代运营
  • wordpress默认小工具栏seo有些什么关键词
  • 别人的网站是怎么做的做一个官网要多少钱
  • wordpress仅显示标题长沙 建站优化
  • 网站的留言怎么做抖音推广方案
  • 解放军工程建设协会网站网站换友链平台
  • 创建全国文明城市总结抖音搜索优化
  • 简洁的个人网站百度指数代表什么
  • 企业网站在哪里建百度搜索引擎优化详解
  • 京东商城网站建设seo管理平台
  • 中文域名网站标识百度公司推广电话
  • 响应式布局网站google adsense
  • 广州专业网站建设哪家公司好网站建设对企业品牌价值提升的影响
  • 网站建设零基础广西网站建设
  • 专业的开发网站建设价格国际购物网站平台有哪些
  • 电商网站建设策划方案职业技能培训网
  • 二手交易平台的网站怎么做中国第三波疫情将在9月份
  • 济南网站怎么做seo百度识图扫一扫
  • 做网站 提要求市场监督管理局电话
  • 杭州做网站公司哪家好生猪价格今日猪价
  • 台湾网站建设公司营销策略分析
  • php动态网站开发关键词排名优化怎么做
  • 武汉市建设厅官方网站河南网站设计
  • 硅云网站建设视频seo关键词优化如何
  • 宣传片制作标准参数百度关键词优化多久上首页
  • 做旅游网站的目的今日国内新闻最新消息10条新闻