机器学习-10-神经网络python实现-从零开始

news2024/9/24 7:24:24

文章目录

    • 总结
    • 参考
    • 本门课程的目标
    • 机器学习定义
    • 从零构建神经网络
      • 手写数据集MNIST介绍
      • 代码读取数据集MNIST
      • 神经网络实现
      • 测试手写的图片
    • 带有反向查询的神经网络实现

总结

本系列是机器学习课程的系列课程,主要介绍基于python实现神经网络。

参考

BP神经网络及python实现(详细)

本文来源原文链接:https://blog.csdn.net/weixin_66845445/article/details/133828686

用Python从0到1实现一个神经网络(附代码)!

python神经网络编程代码https://gitee.com/iamyoyo/makeyourownneuralnetwork.git

本门课程的目标

完成一个特定行业的算法应用全过程:

懂业务+会选择合适的算法+数据处理+算法训练+算法调优+算法融合
+算法评估+持续调优+工程化接口实现

机器学习定义

关于机器学习的定义,Tom Michael Mitchell的这段话被广泛引用:
对于某类任务T性能度量P,如果一个计算机程序在T上其性能P随着经验E而自我完善,那么我们称这个计算机程序从经验E中学习
在这里插入图片描述

从零构建神经网络

手写数据集MNIST介绍

mnist_dataset

MNIST数据集是一个包含大量手写数字的集合。 在图像处理领域中,它是一个非常受欢迎的数据集。 经常被用于评估机器学习算法的性能。 MNIST是改进的标准与技术研究所数据库的简称。 MNIST 包含了一个由 70,000 个 28 x 28 的手写数字图像组成的集合,涵盖了从0到9的数字。

本文通过神经网络基于MNIST数据集进行手写识别。

代码读取数据集MNIST

导入库

import numpy
import matplotlib.pyplot

读取mnist_train_100.csv

# open the CSV file and read its contents into a list
data_file = open("mnist_dataset/mnist_train_100.csv", 'r')
data_list = data_file.readlines()
data_file.close()

查看数据集的长度

# check the number of data records (examples)
len(data_list)
# 输出为 100

查看一条数据,这个数据是手写数字的像素值

# show a dataset record
# the first number is the label, the rest are pixel colour values (greyscale 0-255)
data_list[1]

输出为:
在这里插入图片描述
需要注意的是,这个字符串的第一个字为真实label,比如

data_list[50]

输出为:
在这里插入图片描述

这个输出看不懂,因为这是一个很长的字符串,我们对其进行按照逗号进行分割,然后输出为28*28的,就能看出来了

# take the data from a record, rearrange it into a 28*28 array and plot it as an image
all_values = data_list[50].split(',')
num=0
for i in all_values[1:]:
    num = num +1
    print("%-3s"%(i),end=' ')
    if num==28:
        num = 0
        print('',end='\n')

输出为:
在这里插入图片描述

通过用图片的方式查看

# take the data from a record, rearrange it into a 28*28 array and plot it as an image
all_values = data_list[50].split(',')
image_array = numpy.asfarray(all_values[1:]).reshape((28,28))
matplotlib.pyplot.imshow(image_array, cmap='Greys', interpolation='None')

输出为:
在这里插入图片描述

这个像素值为0-255,对其进行归一化操作

# scale input to range 0.01 to 1.00
scaled_input = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01
# print(scaled_input)
scaled_input

输出为:
在这里插入图片描述

构建一个包含十个输出的标签

#output nodes is 10 (example)
onodes = 10
targets = numpy.zeros(onodes) + 0.01
targets[int(all_values[0])] = 0.99
# print(targets)
targets

输出为:
在这里插入图片描述

神经网络实现

导入库

import numpy
# scipy.special for the sigmoid function expit()
import scipy.special
# library for plotting arrays
import matplotlib.pyplot

神经网络实现

# neural network class definition
# 神经网络类定义
class neuralNetwork:
    
    
    # initialise the neural network
    # 初始化神经网络
    def __init__(self, inputnodes, hiddennodes, outputnodes, learningrate):
        # set number of nodes in each input, hidden, output layer
        # 设置每个输入、隐藏、输出层的节点数
        self.inodes = inputnodes
        self.hnodes = hiddennodes
        self.onodes = outputnodes
        
        # link weight matrices, wih and who
        # weights inside the arrays are w_i_j, where link is from node i to node j in the next layer
        # w11 w21
        # w12 w22 etc 
        # 链接权重矩阵,wih和who
        # 数组内的权重w_i_j,链接从节点i到下一层的节点j
        # w11 w21
        # w12 w22 等等
        self.wih = numpy.random.normal(0.0, pow(self.inodes, -0.5), (self.hnodes, self.inodes))
        self.who = numpy.random.normal(0.0, pow(self.hnodes, -0.5), (self.onodes, self.hnodes))

        # learning rate 学习率
        self.lr = learningrate
        
        # activation function is the sigmoid function
        # 激活函数是sigmoid函数
        self.activation_function = lambda x: scipy.special.expit(x)
        
        pass

    
    # train the neural network
    # 训练神经网络
    def train(self, inputs_list, targets_list):
        # convert inputs list to 2d array
        # 将输入列表转换为2d数组
        inputs = numpy.array(inputs_list, ndmin=2).T
        targets = numpy.array(targets_list, ndmin=2).T
        
        # calculate signals into hidden layer
        # 计算输入到隐藏层的信号
        hidden_inputs = numpy.dot(self.wih, inputs)
        # calculate the signals emerging from hidden layer
        # 计算从隐藏层输出的信号
        hidden_outputs = self.activation_function(hidden_inputs)
        
        # calculate signals into final output layer
        # 计算最终输出层的信号
        final_inputs = numpy.dot(self.who, hidden_outputs)
        # calculate the signals emerging from final output layer
        # 计算从最终输出层输出的信号
        final_outputs = self.activation_function(final_inputs)
        
        # output layer error is the (target - actual)
        # 输出层误差是(目标 - 实际)
        output_errors = targets - final_outputs
        # hidden layer error is the output_errors, split by weights, recombined at hidden nodes
        # 隐藏层误差是输出层误差,按权重分解,在隐藏节点重新组合
        hidden_errors = numpy.dot(self.who.T, output_errors) 
        
        # update the weights for the links between the hidden and output layers
        # 更新隐藏层和输出层之间的权重
        self.who += self.lr * numpy.dot((output_errors * final_outputs * (1.0 - final_outputs)), numpy.transpose(hidden_outputs))
        
        # update the weights for the links between the input and hidden layers
        # 更新输入层和隐藏层之间的权重
        self.wih += self.lr * numpy.dot((hidden_errors * hidden_outputs * (1.0 - hidden_outputs)), numpy.transpose(inputs))
        
        pass

    
    # query the neural network
    # 查询神经网络
    def query(self, inputs_list):
        # convert inputs list to 2d array
        # 将输入列表转换为2d数组
        inputs = numpy.array(inputs_list, ndmin=2).T
        
        # calculate signals into hidden layer
        # 计算输入到隐藏层的信号
        hidden_inputs = numpy.dot(self.wih, inputs)
        # calculate the signals emerging from hidden layer
        # 计算从隐藏层输出的信号
        hidden_outputs = self.activation_function(hidden_inputs)
        
        # calculate signals into final output layer
        # 计算最终输出层的信号
        final_inputs = numpy.dot(self.who, hidden_outputs)
        # calculate the signals emerging from final output layer
        # 计算从最终输出层输出的信号
        final_outputs = self.activation_function(final_inputs)
        
        return final_outputs

定义参数,并初始化神经网络

# number of input, hidden and output nodes
input_nodes = 784
hidden_nodes = 200
output_nodes = 10

# learning rate
learning_rate = 0.1

# create instance of neural network
n = neuralNetwork(input_nodes,hidden_nodes,output_nodes, learning_rate)
n # <__main__.neuralNetwork at 0x2778590e5e0>

查看数据集

# load the mnist training data CSV file into a list
training_data_file = open("mnist_dataset/mnist_train.csv", 'r')
training_data_list = training_data_file.readlines()
training_data_file.close()
len(training_data_list) # 60001
# 其中第1行为列名 ,后面需要去掉,只保留后60000条

开始训练,该步骤需要等待一会,才能训练完成

# train the neural network
# 训练神经网络
# epochs is the number of times the training data set is used for training
# epochs次数,循环训练5次
epochs = 5

for e in range(epochs):
    # go through all records in the training data set
    # 每次取60000条数据,剔除列名
    for record in training_data_list[1:]:
        # split the record by the ',' commas
        # 用逗号分割
        all_values = record.split(',')
        # scale and shift the inputs
        # 对图像的像素值进行归一化操作
        inputs = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01
        # create the target output values (all 0.01, except the desired label which is 0.99)
        # 创建一个包含十个输出的向量,初始值为0.01
        targets = numpy.zeros(output_nodes) + 0.01
        # all_values[0] is the target label for this record
        # 对 label的 位置设置为0.99
        targets[int(all_values[0])] = 0.99
        # 开始训练
        n.train(inputs, targets)
        pass
    pass

查看训练后的权重

n.who.shape # (10, 200)
n.who

输出为:
在这里插入图片描述

n.wih.shape # ((200, 784)
n.wih

输出为:
在这里插入图片描述

查看测试集

# load the mnist test data CSV file into a list
test_data_file = open("mnist_dataset/mnist_test.csv", 'r')
test_data_list = test_data_file.readlines()
test_data_file.close()
len(test_data_list) # 10001
# 其中第1行为列名 ,后面需要去掉,只保留后10000条

预测测试集

# test the neural network
# 测试网络
# scorecard for how well the network performs, initially empty
# 计算网络性能,初始为空
scorecard = []

# go through all the records in the test data set
# 传入所有的测试集
for record in test_data_list[1:]:
    # split the record by the ',' commas
    # 使用逗号分割
    all_values = record.split(',')
    # correct answer is first value
    # 获取当前的测试集的label
    correct_label = int(all_values[0])
    # scale and shift the inputs
    # 归一化操作
    inputs = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01
    # query the network
    # 对测试集进行预测
    outputs = n.query(inputs)
    # the index of the highest value corresponds to the label
    # 获取输出中最大的概率的位置
    label = numpy.argmax(outputs)
    # append correct or incorrect to list
    # 按照预测的正确与否分别填入1和0
    if (label == correct_label):
        # network's answer matches correct answer, add 1 to scorecard
        # 答案匹配正确,输入1
        scorecard.append(1)
    else:
        # network's answer doesn't match correct answer, add 0 to scorecard
        # 答案不匹配,输入0
        scorecard.append(0)
        pass
    
    pass

计算网络性能

# calculate the performance score, the fraction of correct answers
scorecard_array = numpy.asarray(scorecard)
print ("performance = ", scorecard_array.sum() / scorecard_array.size)
# performance =  0.9725

输出为:

performance = 0.9725

测试手写的图片

导入库

# helper to load data from PNG image files
import imageio.v3
# glob helps select multiple files using patterns
import glob

定义数据集列表

# our own image test data set
our_own_dataset = []

读取多个数据

# glob.glob获取一个可编历对象,使用它可以逐个获取匹配的文件路径名。glob.glob同时获取所有的匹配路径
for image_file_name in glob.glob('my_own_images/2828_my_own_?.png'):
    # 输出 匹配到的文件
    print ("loading ... ", image_file_name)
    # use the filename to set the correct label
    # 文件名中包含了文件的正确标签
    label = int(image_file_name[-5:-4])
    # load image data from png files into an array
    # 把 图片转换为 文本
    img_array = imageio.v3.imread(image_file_name, mode='F')
    # reshape from 28x28 to list of 784 values, invert values
    # 把28*28的矩阵转换为 784和1维
    img_data  = 255.0 - img_array.reshape(784)
    # then scale data to range from 0.01 to 1.0
    # 对数据进行归一化操作,最小值为0.01
    img_data = (img_data / 255.0 * 0.99) + 0.01
    print(numpy.min(img_data))
    print(numpy.max(img_data))
    # append label and image data  to test data set
    # 把 laebl和图片拼接起来
    record = numpy.append(label,img_data)
    print(record.shape)
    # 把封装好的 一维存储在列表中
    our_own_dataset.append(record)
    pass

读取的数据如下:

在这里插入图片描述
输出为,
在这里插入图片描述

查看手写的图片

matplotlib.pyplot.imshow(our_own_dataset[0][1:].reshape(28,28), cmap='Greys', interpolation='None')

输出为:
在这里插入图片描述

输出对应的像数值

# print(our_own_dataset[0])
print(our_own_dataset[0][0],"\n",our_own_dataset[0][1:20])

输出如下:
在这里插入图片描述

测试手写数据效果

own_list = []
for i in our_own_dataset:
    correct_label = i[0]
    img_data = i[1:]
    # query the network
    outputs = n.query(img_data)
#     print ('outputs预测',outputs)

    # the index of the highest value corresponds to the label
    label = numpy.argmax(outputs)
    print('真实',correct_label,"network says ", label)
    if (label == correct_label):
        # network's answer matches correct answer, add 1 to scorecard
        own_list.append(1)
    else:
        # network's answer doesn't match correct answer, add 0 to scorecard
        own_list.append(0)
        
print("own_list",own_list)

输出为:
在这里插入图片描述

带有反向查询的神经网络实现

该部分代码与 从零构建神经网络大多类似,代码如下:

导入库

import numpy
# scipy.special for the sigmoid function expit(), and its inverse logit()
import scipy.special
# library for plotting arrays
import matplotlib.pyplot

定义带有反向查询的神经网络

# neural network class definition
# 神经网络类定义
class neuralNetwork:
    
    
    # initialise the neural network
    # 初始化神经网络
    def __init__(self, inputnodes, hiddennodes, outputnodes, learningrate):
        # set number of nodes in each input, hidden, output layer
        # 设置每个输入、隐藏、输出层的节点数
        self.inodes = inputnodes
        self.hnodes = hiddennodes
        self.onodes = outputnodes
        
        # link weight matrices, wih and who
        # weights inside the arrays are w_i_j, where link is from node i to node j in the next layer
        # w11 w21
        # w12 w22 etc 
        # 链接权重矩阵,wih和who
        # 数组内的权重w_i_j,链接从节点i到下一层的节点j
        # w11 w21
        # w12 w22 等等
        self.wih = numpy.random.normal(0.0, pow(self.inodes, -0.5), (self.hnodes, self.inodes))
        self.who = numpy.random.normal(0.0, pow(self.hnodes, -0.5), (self.onodes, self.hnodes))

        # learning rate 学习率
        self.lr = learningrate
        
        # activation function is the sigmoid function
        # 激活函数是sigmoid函数
        self.activation_function = lambda x: scipy.special.expit(x)
        self.inverse_activation_function = lambda x: scipy.special.logit(x)
        
        pass

    
    # train the neural network
    # 训练神经网络
    def train(self, inputs_list, targets_list):
        # convert inputs list to 2d array
        # 将输入列表转换为2d数组
        inputs = numpy.array(inputs_list, ndmin=2).T
        targets = numpy.array(targets_list, ndmin=2).T
        
        # calculate signals into hidden layer
        # 计算输入到隐藏层的信号
        hidden_inputs = numpy.dot(self.wih, inputs)
        # calculate the signals emerging from hidden layer
        # 计算从隐藏层输出的信号
        hidden_outputs = self.activation_function(hidden_inputs)
        
        # calculate signals into final output layer
        # 计算最终输出层的信号
        final_inputs = numpy.dot(self.who, hidden_outputs)
        # calculate the signals emerging from final output layer
        # 计算从最终输出层输出的信号
        final_outputs = self.activation_function(final_inputs)
        
        # output layer error is the (target - actual)
        # 输出层误差是(目标 - 实际)
        output_errors = targets - final_outputs
        # hidden layer error is the output_errors, split by weights, recombined at hidden nodes
        # 隐藏层误差是输出层误差,按权重分解,在隐藏节点重新组合
        hidden_errors = numpy.dot(self.who.T, output_errors) 
        
        # update the weights for the links between the hidden and output layers
        # 更新隐藏层和输出层之间的权重
        self.who += self.lr * numpy.dot((output_errors * final_outputs * (1.0 - final_outputs)), numpy.transpose(hidden_outputs))
        
        # update the weights for the links between the input and hidden layers
        # 更新输入层和隐藏层之间的权重
        self.wih += self.lr * numpy.dot((hidden_errors * hidden_outputs * (1.0 - hidden_outputs)), numpy.transpose(inputs))
        
        pass

    
    # query the neural network
    # 查询神经网络
    def query(self, inputs_list):
        # convert inputs list to 2d array
        # 将输入列表转换为2d数组
        inputs = numpy.array(inputs_list, ndmin=2).T
        
        # calculate signals into hidden layer
        # 计算输入到隐藏层的信号
        hidden_inputs = numpy.dot(self.wih, inputs)
        # calculate the signals emerging from hidden layer
        # 计算从隐藏层输出的信号
        hidden_outputs = self.activation_function(hidden_inputs)
        
        # calculate signals into final output layer
        # 计算最终输出层的信号
        final_inputs = numpy.dot(self.who, hidden_outputs)
        # calculate the signals emerging from final output layer
        # 计算从最终输出层输出的信号
        final_outputs = self.activation_function(final_inputs)
        
        return final_outputs

    
    # backquery the neural network
    # we'll use the same termnimology to each item, 
    # eg target are the values at the right of the network, albeit used as input
    # eg hidden_output is the signal to the right of the middle nodes
    # 反向 查询
    def backquery(self, targets_list):
        # transpose the targets list to a vertical array
        # 将目标列表转置为垂直数组
        final_outputs = numpy.array(targets_list, ndmin=2).T
        
        # calculate the signal into the final output layer
        # 计算最终输出层的输入信号
        final_inputs = self.inverse_activation_function(final_outputs)

        # calculate the signal out of the hidden layer
        # 计算隐藏层的输出信号
        hidden_outputs = numpy.dot(self.who.T, final_inputs)
        # scale them back to 0.01 to .99
        # 将隐藏层的输出信号缩放到0.01到0.99之间
        hidden_outputs -= numpy.min(hidden_outputs)
        hidden_outputs /= numpy.max(hidden_outputs)
        hidden_outputs *= 0.98
        hidden_outputs += 0.01
        
        # calculate the signal into the hidden layer
        # 计算隐藏层的输入信号
        hidden_inputs = self.inverse_activation_function(hidden_outputs)
        
        # calculate the signal out of the input layer
        # 计算输入层的输出信号
        inputs = numpy.dot(self.wih.T, hidden_inputs)
        # scale them back to 0.01 to .99
        # 将输入层的输出信号缩放到0.01到0.99之间
        inputs -= numpy.min(inputs)
        inputs /= numpy.max(inputs)
        inputs *= 0.98
        inputs += 0.01
        
        return inputs
    

初始化神经网络

# number of input, hidden and output nodes
# 定义网络的输入 隐藏 输出节点数量
input_nodes = 784
hidden_nodes = 200
output_nodes = 10

# learning rate
# 学习率
learning_rate = 0.1

# create instance of neural network
# 实例化网络
n = neuralNetwork(input_nodes,hidden_nodes,output_nodes, learning_rate)

加载数据集

# load the mnist training data CSV file into a list
training_data_file = open("mnist_dataset/mnist_train.csv", 'r')
training_data_list = training_data_file.readlines()
training_data_file.close()

训练模型

# train the neural network

# epochs is the number of times the training data set is used for training
epochs = 5

for e in range(epochs):
    print("\n epochs------->",e)
    num = 0
    # go through all records in the training data set
    data_list = len(training_data_list[1:])
    for record in training_data_list[1:]:
        # split the record by the ',' commas
        all_values = record.split(',')
        # scale and shift the inputs
        inputs = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01
        # create the target output values (all 0.01, except the desired label which is 0.99)
        targets = numpy.zeros(output_nodes) + 0.01
        # all_values[0] is the target label for this record
        targets[int(all_values[0])] = 0.99
        n.train(inputs, targets)
        num +=1 
        if num %500==0:
            print("\r epochs {} 当前进度为 {}".format(e,num/data_list),end="")
        pass
    pass

输出为:

epochs-------> 0
epochs 0 当前进度为 1.091666666666666744
epochs-------> 1
epochs 1 当前进度为 1.091666666666666744
epochs-------> 2
epochs 2 当前进度为 1.091666666666666744
epochs-------> 3
epochs 3 当前进度为 1.091666666666666744
epochs-------> 4
epochs 4 当前进度为 1.091666666666666744

加载测试数据

# load the mnist test data CSV file into a list
test_data_file = open("mnist_dataset/mnist_test.csv", 'r')
test_data_list = test_data_file.readlines()
test_data_file.close()

加载测试数据

# test the neural network

# scorecard for how well the network performs, initially empty
scorecard = []

# go through all the records in the test data set
for record in test_data_list[1:]:
    # split the record by the ',' commas
    all_values = record.split(',')
    # correct answer is first value
    correct_label = int(all_values[0])
    # scale and shift the inputs
    inputs = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01
    # query the network
    outputs = n.query(inputs)
    # the index of the highest value corresponds to the label
    label = numpy.argmax(outputs)
    # append correct or incorrect to list
    if (label == correct_label):
        # network's answer matches correct answer, add 1 to scorecard
        scorecard.append(1)
    else:
        # network's answer doesn't match correct answer, add 0 to scorecard
        scorecard.append(0)
        pass
    
    pass

计算模型性能

# calculate the performance score, the fraction of correct answers
scorecard_array = numpy.asarray(scorecard)
print ("performance = ", scorecard_array.sum() / scorecard_array.size)
# performance =  0.9737

根据模型反向生成图片

# run the network backwards, given a label, see what image it produces

# label to test
label = 0
# create the output signals for this label
targets = numpy.zeros(output_nodes) + 0.01
# all_values[0] is the target label for this record
targets[label] = 0.99
print(targets)

# get image data
image_data = n.backquery(targets)

# plot image data
matplotlib.pyplot.imshow(image_data.reshape(28,28), cmap='Greys', interpolation='None')

输出为:
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1616176.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

VUE 项目 自动按需导入

你是否有这样的苦恼&#xff0c;每个.vue都需要导入所需的vue各个方法 unplugin-auto-import 库 Vite、Webpack和Rollup的按需自动导入API 本章提供Vite、Webpack中使用说明 1. 安装 npm i -D unplugin-auto-import 2. config.js 配置文件内追加配置 2.1 Vite // vite.conf…

计算机网络—— book

文章目录 一、概述1.互联网的核心部分1&#xff0e;电路交换的主要特点2&#xff0e;分组交换的主要特点 2.计算机网络的性能1&#xff0e;速率2&#xff0e;带宽3&#xff0e;吞吐量4&#xff0e;时延5&#xff0e;利用率 3.计算机网络体系结构协议与划分层次具有五层协议的体…

达芬奇调色:色彩理论入门

写在前面 整理一些达芬奇调色的笔记博文内容涉及&#xff1a; 一级调色是什么&#xff0c;以及 调色素材格式 log&#xff0c;raw&#xff0c;rec709 简单认知理解不足小伙伴帮忙指正 不必太纠结于当下&#xff0c;也不必太忧虑未来&#xff0c;当你经历过一些事情的时候&#…

四、【易 AI】模型渲染与透明背景

美恶相饰,命曰复周,物极则反,命曰环流。 ——《鹖冠子环流》 一、渲染帧率 以上两种移植方式,均可正常渲染出模型,但是画面是静止的,是因为没有调用 update 方法来刷新窗口渲染内容,我们可以通过 QTimer 来控制渲染帧率,以 MyOpenGLWindow 为例,做以下修改, #ifnde…

GHO文件安装到Vmware的两种姿势

1、使用 Ghost11.5.1.2269 将gho转换为vmdk文件(虚拟机硬盘)&#xff0c;Vmware新建虚拟机自定义配置&#xff0c;然后添加已有的虚拟硬盘文件。 注意ghost的版本&#xff0c;如果你是用Ghost11.5备份的gho文件&#xff0c;再用Ghost12把gho文件转换为vmdk&#xff0c;则vmdk文…

C++及QT的线程学习

目录 一. 线程学习 二. 学习线程当中&#xff0c;得到的未知。 1. 了解以下MainWindow和main的关系 2. []()匿名函数 有函数体&#xff0c;没有函数名. 3. join和detach都是用来管理线程的生命周期的&#xff0c;它们的区别在于线程结束和资源的回收。 4. operator()() 仿…

Spark-机器学习(4)回归学习之逻辑回归

在之前的文章中&#xff0c;我们来学习我们回归中的线性回归&#xff0c;了解了它的算法&#xff0c;知道了它的用法&#xff0c;并带来了简单案例。想了解的朋友可以查看这篇文章。同时&#xff0c;希望我的文章能帮助到你&#xff0c;如果觉得我的文章写的不错&#xff0c;请…

管理集群工具之LVS

管理集群工具之LVS 集群概念 将很多机器组织在一起&#xff0c;作为一个整体对外提供服务集群在扩展性、性能方面都可以做到很灵活集群分类 负载均衡集群&#xff1a;Load Balance高可用集群&#xff1a;High Availability高性能计算&#xff1a;High Performance Computing …

OpenCV轻松入门(九)——使用第三方库imgaug自定义数据增强器

安装命令&#xff1a;pip install imgaug 代码实现&#xff1a; import cv2 import random import matplotlib.pyplot as pltfrom imgaug import augmenters as iaa # 数据增强——缩放效果 def zoom_img(img):# 获取一个1-1.3倍的线性图像处理器&#xff0c;scale参数是缩放范…

计算机视觉 | 交通信号灯状态的检测和识别

Hi&#xff0c;大家好&#xff0c;我是半亩花海。本项目旨在使用计算机视觉技术检测交通信号灯的状态&#xff0c;主要针对红色和绿色信号灯的识别。通过分析输入图像中的像素颜色信息&#xff0c;利用OpenCV库实现对信号灯状态的检测和识别。 目录 一、项目背景 二、项目功能…

项目大集成

一 keeplived 高可用 192.168.11.11nginx keeplived192.168.11.12nginx keeplived 两台均编译安装服务器 1 主服务器修改文件&#xff1a; 2 备服务器修改文本 scp keepalived.conf 192.168.11.12:/etc/keepalived/ 3 给主服务器添加虚拟ip ifconfig ens33:0 192.168…

React.js 3D开发快速入门

如果你对 3D 图形的可能性着迷&#xff0c;但发现从头开始创建 3D 模型的想法是不可能的 - 不用担心&#xff01; Three.js 是一个强大的 JavaScript 库&#xff0c;它可以帮助我们轻松地将现有的 3D 模型集成到 React 应用程序中。因此&#xff0c;在本文中&#xff0c;我将深…

DHCP服务器配置故障转移后显示红色箭头、与伙伴服务器失去联系的解决方案

一、遇到的故障现象&#xff1a; &#xff08;主DHCP服务器与备用DHCP服务器连通性正常&#xff0c;在故障转移选项卡上却显示与伙伴失去联系、伙伴关闭&#xff0c;且ipv4协议旁边显示一个红色的小箭头&#xff09;&#xff0c;正常情况下是绿色 &#xff08;一&#xff09;…

Jenkins CI/CD 持续集成专题二 Jenkins 相关问题汇总

一 问题一 pod [!] Unknown command: package 1.1 如果没有安装过cocoapods-packager&#xff0c;安装cocoapods-packager&#xff0c;sudo gem install cocoapods-packager 1.2 如果已经安装cocoapods-packager&#xff0c;还是出现上面的错误&#xff0c;有可能是pod的安…

通过创新的MoE架构插件缓解大型语言模型的世界知识遗忘问题

在人工智能领域&#xff0c;大型语言模型&#xff08;LLM&#xff09;的微调是提升模型在特定任务上性能的关键步骤。然而&#xff0c;一个挑战在于&#xff0c;当引入大量微调数据时&#xff0c;模型可能会遗忘其在预训练阶段学到的世界知识&#xff0c;这被称为“世界知识遗忘…

Valentina Studio Pro for Mac:强大的数据库管理工具

Valentina Studio Pro for Mac是一款功能全面、操作高效的数据库管理工具&#xff0c;专为Mac用户设计&#xff0c;旨在帮助用户轻松管理各种类型的数据库。 Valentina Studio Pro for Mac v13.10激活版下载 该软件拥有直观的用户界面&#xff0c;使得数据库管理变得简单直观。…

JS - 以工厂模式和原型模式方式建造对象、JS的垃级回收机制、数组的使用

创建对象的方式 使用工厂方法来建造对象 在JS中我们可以通过以下方式进行创建对象&#xff1a; var obj {name:"孙悟空",age:18,gender:"男",sayName:function(){alert(this.name);}};var obj2 {name:"猪八戒",age:28,gender:"男",…

学习ArkTS -- 状态管理

装饰器 State 在声明式UI中&#xff0c;是以状态驱动试图更新&#xff1a; 状态&#xff08;State&#xff09;&#xff1a;指驱动视图更新的数据&#xff08;被装饰器标记的变量&#xff09; 视图&#xff08;View&#xff09;&#xff1a;基于UI描述渲染得到用户界面 说明…

Next.js+React+Node系统实战,搞定SSR服务器渲染

Next.jsReactNode系统实战&#xff0c;搞定SSR服务器渲染 Next.js React Node.js 实战&#xff1a;实现服务器端渲染&#xff08;SSR&#xff09; 项目概述 在这个项目中&#xff0c;我们将探讨如何使用 Next.js、React 和 Node.js 来构建一个服务器渲染的 web 应用程序。通…

无人驾驶 自动驾驶汽车 环境感知 精准定位 决策与规划 控制与执行 高精地图与车联网V2X 深度神经网络学习 深度强化学习 Apollo

无人驾驶 百度apollo课程 1-5 百度apollo课程 6-8 七月在线 无人驾驶系列知识入门到提高 当今,自动驾驶技术已经成为整个汽车产业的最新发展方向。应用自动驾驶技术可以全面提升汽车驾驶的安全性、舒适性,满足更高层次的市场需求等。自动驾驶技术得益于人工智能技术的应用…