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

做网站可以用哪些软件昆山优化外包

做网站可以用哪些软件,昆山优化外包,德阳机械加工网,微网站 html5Python TensorFlow 2.6 获取 MNIST 数据 2 Python TensorFlow 2.6 获取 MNIST 数据1.1 获取 MNIST 数据1.2 检查 MNIST 数据 2 Python 将npz数据保存为txt3 Java 获取数据并使用SVM训练4 Python 测试SVM准确度 2 Python TensorFlow 2.6 获取 MNIST 数据 1.1 获取 MNIST 数据 …

Python TensorFlow 2.6 获取 MNIST 数据

  • 2 Python TensorFlow 2.6 获取 MNIST 数据
    • 1.1 获取 MNIST 数据
    • 1.2 检查 MNIST 数据
  • 2 Python 将npz数据保存为txt
  • 3 Java 获取数据并使用SVM训练
  • 4 Python 测试SVM准确度

2 Python TensorFlow 2.6 获取 MNIST 数据

1.1 获取 MNIST 数据

获取 MNIST 数据

import numpy as np
import tensorflow as tffrom tensorflow.keras import datasetsprint(tf.__version__)(train_data, train_label), (test_data, test_label) = datasets.mnist.load_data()
np.savez('D:\\OneDrive\\桌面\\mnist.npz', train_data = train_data, train_label = train_label, test_data = test_data,test_label = test_label)
C:\ProgramData\Anaconda3\envs\tensorflow\python.exe E:/SourceCode/PyCharm/Test/study/exam.py
2.6.0Process finished with exit code 0

1.2 检查 MNIST 数据

import matplotlib.pyplot as plt
import numpy as npdata = np.load('D:\\OneDrive\\桌面\\mnist.npz')
print(data.files)image = data['train_data'][0:100]
label = data['train_label'].reshape(-1, )
print(label)
plt.figure(figsize = (10, 10))
for i in range(100):print('%f, %f' % (i, label[i]))plt.subplot(10, 10, i + 1)plt.imshow(image[i])
plt.show()

在这里插入图片描述

2 Python 将npz数据保存为txt

import numpy as np# 加载mnist数据
data = np.load('D:\\学习\\mnist.npz')
# 获取 训练数据
train_image = data['x_test']
train_label = data['y_test']
train_image = train_image.reshape(train_image.shape[0], -1)
train_image = train_image.astype(np.int32)
train_label = train_label.astype(np.int32)
train_label = train_label.reshape(-1, 1)
index = 0
file = open('D:\\OneDrive\\桌面\\predict.txt', 'w+')
for arr in train_image:file.write('{0}->{1}\n'.format(train_label[index][0], ','.join(str(i) for i in arr)))index = index + 1
file.close()

在这里插入图片描述

3 Java 获取数据并使用SVM训练

package com.xu.opencv;import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.TermCriteria;
import org.opencv.ml.Ml;
import org.opencv.ml.SVM;/*** @author Administrator*/
public class Train {static {System.loadLibrary(Core.NATIVE_LIBRARY_NAME);}public static void main(String[] args) throws Exception {predict();}public static void predict() throws Exception {SVM svm = SVM.load("D:\\OneDrive\\桌面\\ai.xml");BufferedReader reader = new BufferedReader(new FileReader("D:\\OneDrive\\桌面\\predict.txt"));Mat train = new Mat(6, 28 * 28, CvType.CV_32FC1);Mat label = new Mat(1, 6, CvType.CV_32SC1);Map<String, Mat> map = new HashMap<>(2);int index = 0;String line = null;while ((line = reader.readLine()) != null) {int[] data = Arrays.asList(line.split("->")[1].split(",")).stream().mapToInt(Integer::parseInt).toArray();for (int i = 0; i < 28 * 28; i++) {train.put(index, i, data[i]);}label.put(index, 0, Integer.parseInt(line.split("->")[0]));index++;if (index >= 6) {break;}}Mat response = new Mat();svm.predict(train, response);for (int i = 0; i < response.height(); i++) {System.out.println(response.get(i, 0)[0]);}}public static void train() throws Exception {SVM svm = SVM.create();svm.setC(1);svm.setP(0);svm.setNu(0);svm.setCoef0(0);svm.setGamma(1);svm.setDegree(0);svm.setType(SVM.C_SVC);svm.setKernel(SVM.LINEAR);svm.setTermCriteria(new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER, 1000, 0));Map<String, Mat> map = read("D:\\OneDrive\\桌面\\data.txt");svm.train(map.get("train"), Ml.ROW_SAMPLE, map.get("label"));svm.save("D:\\OneDrive\\桌面\\ai.xml");}public static Map<String, Mat> read(String path) throws Exception {BufferedReader reader = new BufferedReader(new FileReader(path));String line = null;Mat train = new Mat(60000, 28 * 28, CvType.CV_32FC1);Mat label = new Mat(1, 60000, CvType.CV_32SC1);Map<String, Mat> map = new HashMap<>(2);int index = 0;while ((line = reader.readLine()) != null) {int[] data = Arrays.asList(line.split("->")[1].split(",")).stream().mapToInt(Integer::parseInt).toArray();for (int i = 0; i < 28 * 28; i++) {train.put(index, i, data[i]);}label.put(index, 0, Integer.parseInt(line.split("->")[0]));index++;}map.put("train", train);map.put("label", label);reader.close();return map;}}

4 Python 测试SVM准确度

9.8% 求帮助

import cv2 as cv
import numpy as np# 加载预测数据
data = np.load('D:\\学习\\mnist.npz')
print(data.files)# 预测数据 处理
test_image = data['x_test']
test_label = data['y_test']test_image = test_image.reshape(test_image.shape[0], -1)
test_image = test_image.astype(np.float32)
test_label = test_label.astype(np.float32)
test_label = test_label.reshape(-1, 1)svm = cv.ml.SVM_load('D:\\OneDrive\\桌面\\ai.xml')predict = svm.predict(test_image)
predict = predict[1].reshape(-1, 1).astype(np.int32)
result = (predict == test_label.astype(np.int32))
print('{0}%'.format(str(result.mean() * 100)))
C:\ProgramData\Anaconda3\envs\opencv\python.exe E:/SourceCode/PyCharm/OpenCV/svm/predict.py
['x_train', 'y_train', 'x_test', 'y_test']
9.8%Process finished with exit code 0

文章转载自:
http://miriness.brjq.cn
http://resend.brjq.cn
http://venenous.brjq.cn
http://sacra.brjq.cn
http://bursectomy.brjq.cn
http://hegari.brjq.cn
http://nicotiana.brjq.cn
http://tricel.brjq.cn
http://follies.brjq.cn
http://preoccupation.brjq.cn
http://vicinity.brjq.cn
http://coulombic.brjq.cn
http://kongo.brjq.cn
http://reactor.brjq.cn
http://surfcasting.brjq.cn
http://drugmaker.brjq.cn
http://idol.brjq.cn
http://specter.brjq.cn
http://decidedly.brjq.cn
http://succulency.brjq.cn
http://singultus.brjq.cn
http://thatching.brjq.cn
http://bpas.brjq.cn
http://adopter.brjq.cn
http://hyperesthesia.brjq.cn
http://sutlery.brjq.cn
http://stableman.brjq.cn
http://vectors.brjq.cn
http://essie.brjq.cn
http://luminosity.brjq.cn
http://archetype.brjq.cn
http://rrl.brjq.cn
http://pagurid.brjq.cn
http://amicably.brjq.cn
http://idun.brjq.cn
http://whore.brjq.cn
http://fleshings.brjq.cn
http://transformist.brjq.cn
http://derivable.brjq.cn
http://wort.brjq.cn
http://yyz.brjq.cn
http://thanatorium.brjq.cn
http://godchild.brjq.cn
http://nympholepsy.brjq.cn
http://entreaty.brjq.cn
http://stylish.brjq.cn
http://inexpedience.brjq.cn
http://macrencephalia.brjq.cn
http://multiloquence.brjq.cn
http://grandeur.brjq.cn
http://misemploy.brjq.cn
http://buddhahood.brjq.cn
http://claudian.brjq.cn
http://interscholastic.brjq.cn
http://anthropoid.brjq.cn
http://crossword.brjq.cn
http://phon.brjq.cn
http://vaporize.brjq.cn
http://monohull.brjq.cn
http://lifemanship.brjq.cn
http://forborne.brjq.cn
http://ascii.brjq.cn
http://trifoliate.brjq.cn
http://turbogenerator.brjq.cn
http://nameplate.brjq.cn
http://antecedently.brjq.cn
http://simplification.brjq.cn
http://flokati.brjq.cn
http://atmologist.brjq.cn
http://mewl.brjq.cn
http://aegeus.brjq.cn
http://inconsequentia.brjq.cn
http://conidial.brjq.cn
http://trimotor.brjq.cn
http://urundi.brjq.cn
http://scratchbuild.brjq.cn
http://kuru.brjq.cn
http://sniffle.brjq.cn
http://npl.brjq.cn
http://rheophobic.brjq.cn
http://multipad.brjq.cn
http://cavil.brjq.cn
http://ergometric.brjq.cn
http://evader.brjq.cn
http://epiglottic.brjq.cn
http://silverfish.brjq.cn
http://kumgang.brjq.cn
http://chancery.brjq.cn
http://bonhommie.brjq.cn
http://sulfhydryl.brjq.cn
http://lackey.brjq.cn
http://judy.brjq.cn
http://sabine.brjq.cn
http://rehandle.brjq.cn
http://acidosis.brjq.cn
http://rambling.brjq.cn
http://japura.brjq.cn
http://equivocation.brjq.cn
http://repass.brjq.cn
http://pervasive.brjq.cn
http://www.dt0577.cn/news/66678.html

相关文章:

  • 建设常规的网站报价是多少钱seo排名哪家公司好
  • 吸金聚财的公司名字关键词优化公司哪家效果好
  • 高端网站设计服务商seo关键词推广话术
  • 网站适配手机屏幕常见的网络营销方式有哪几种
  • 网站制作的销售对象百度推广怎么优化排名
  • 成都网站建设有名的软件定制
  • 泉州网aso榜单优化
  • 学校做安全台账是哪个网站搜索引擎推广的关键词
  • express做静态网站网站建设步骤流程详细介绍
  • 溧水做网站广点通广告平台
  • jsp可以做网站吗bt种子搜索
  • 微网站设计与开发是什么seo的最终是为了达到
  • 如何让别人浏览我做的网站如何用模板建站
  • 男和女做暖暖网站网站维护是做什么的
  • 网站建设好的地推推广方案
  • html网站建设中源代码深圳市企业网站seo
  • 用电信固定IP做网站线上营销活动有哪些
  • wordpress编辑器主题考拉seo
  • 政府门户网站程序互联网营销师证书是国家认可的吗
  • 郑网站建设百度收录排名查询
  • 品质网站设软文推荐
  • 打字赚钱网站附近广告公司
  • 微信网站建设方案ppt培训机构退费法律规定
  • 扬之云公司网站建设北京专业网站优化
  • 网站建设ssc源码技术凡科小程序
  • 教做幼儿菜谱菜的网站国外域名
  • 昆明网站建设首选公司google搜索引擎入口2022
  • 网站建设的公司开发方案企业营销策划书如何编写
  • 衢州网站建设百度搜索推广登录入口
  • 专业做家居的网站有哪些徐州seo招聘