【Python机器学习】实验16 卷积、下采样、经典卷积网络

news2025/1/12 21:02:29

文章目录

  • 卷积、下采样、经典卷积网络
    • 1. 对图像进行卷积处理
    • 2. 池化
    • 3. VGGNET
    • 4. 采用预训练的Resnet实现猫狗识别
  • TensorFlow2.2基本应用
    • 5. 使用深度学习进行手写数字识别

卷积、下采样、经典卷积网络

1. 对图像进行卷积处理

import cv2
path = 'data\instance\p67.jpg' 
input_img = cv2.imread(path)
import cv2 
import numpy as np 
#分别将三个通道进行卷积,然后合并通道

def conv(image, kernel): 
    conv_b = convolve(image[:, :, 0], kernel) 
    conv_g = convolve(image[:, :, 1], kernel) 
    conv_r = convolve(image[:, :, 2], kernel) 
    output = np.dstack([conv_b, conv_g, conv_r]) 
    return output


#卷积处理
def convolve(image, kernel): 
    h_kernel, w_kernel = kernel.shape 
    h_image, w_image = image.shape
    h_output = h_image - h_kernel + 1 
    w_output = w_image - w_kernel + 1 
    output = np.zeros((h_output, w_output), np.uint8) 
    for i in range(h_output): 
        for j in range(w_output): 
            output[i, j] = np.multiply(image[i:i + h_kernel, j:j + w_kernel], kernel).sum() 
    return output

if __name__ == '__main__': 
    path = 'data\instance\p67.jpg' 
    input_img = cv2.imread(path) 
    # 1.锐化卷积核 
    #kernel = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]]) 
    # 2.模糊卷积核
    kernel = np.array([[0.1,0.1,0.1],[0.1,0.2,0.1],[0.1,0.1,0.1]])     
    output_img = conv(input_img, kernel)
    cv2.imwrite(path.replace('.jpg', '-processed.jpg'), output_img) 
    cv2.imshow('Output Image', output_img) 
    cv2.waitKey(0)

2. 池化

img = cv2.imread('data\instance\dog.jpg')
img.shape
(4064, 3216, 3)
import numpy as np
from PIL import Image
import cv2
import matplotlib.pyplot as plt

#均值池化
def AVGpooling(imgData, strdW, strdH):
    W,H = imgData.shape
    newImg = []
    for i in range(0,W,strdW):
        line = []
        for j in range(0,H,strdH):
            x = imgData[i:i+strdW,j:j+strdH]     #获取当前待池化区域
            avgValue=np.sum(x)/(strdW*strdH)  #求该区域的均值
            line.append(avgValue)     
        newImg.append(line)
    return np.array(newImg)

#最大池化
def MAXpooling(imgData, strdW, strdH):
    W,H = imgData.shape
    newImg = []
    for i in range(0,W,strdW):
        line = []
        for j in range(0,H,strdH):
            x = imgData[i:i+strdW,j:j+strdH]    #获取当前待池化区域
            maxValue=np.max(x)            #求该区域的最大值
            line.append(maxValue)        
        newImg.append(line)
    return np.array(newImg)

img = cv2.imread('data\instance\dog.jpg')
imgData= img[:,:,1]   #绿色通道


#显示原图
plt.subplot(221)
plt.imshow(img)
plt.axis('off')

#显示原始绿通道图
plt.subplot(222)
plt.imshow(imgData)
plt.axis('off')

#显示平均池化结果图
AVGimg = AVGpooling(imgData, 2, 2)
plt.subplot(223)
plt.imshow(AVGimg)
plt.axis('off')

#显示最大池化结果图
MAXimg = MAXpooling(imgData, 2, 2)
plt.subplot(224)
plt.imshow(MAXimg)
plt.axis('off')
plt.show()

1

3. VGGNET

import numpy as np 
from tensorflow.keras import backend as K 
import matplotlib.pyplot as plt 
from tensorflow.keras.applications import vgg16   # Keras内置 VGG-16模块,直接可调用。 
from tensorflow.keras.preprocessing import image 
from tensorflow.keras.applications.vgg16 import preprocess_input
import math
input_size = 224   # 网络输入图像的大小,长宽相等 
kernel_size = 64   # 可视化卷积核的大小,长宽相等 
layer_vis = True    # 特征图是否可视化
kernel_vis = True   # 卷积核是否可视化
each_layer = False  # 卷积核可视化是否每层都做
which_layer = 1    # 如果不是每层都做,那么第几个卷积层
path = 'data\instance\p67.jpg' 


img = image.load_img(path, target_size=(input_size, input_size)) 
img = image.img_to_array(img) 
img = np.expand_dims(img, axis=0) 
img = preprocess_input(img)  #标准化预处理
model = vgg16.VGG16(include_top=True, weights='imagenet')


def network_configuration(): 
    all_channels = [64, 64, 64, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512, 512, 512, 512, 512] 
    down_sampling = [1, 1, 1 / 2, 1 / 2, 1 / 2, 1 / 4, 1 / 4, 1 / 4, 1 / 4, 1 / 8, 1 / 8, 1 / 8, 1 / 8, 1 / 16, 1 / 16, 1 / 16, 1 / 16, 1 / 32] 
    conv_layers = [1, 2, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17] 
    conv_channels = [64, 64, 128, 128, 256, 256, 256, 512, 512, 512, 512, 512, 512] 
    return all_channels, down_sampling, conv_layers, conv_channels

def layer_visualization(model, img, layer_num, channel, ds): 
    # 设置可视化的层 
    layer = K.function([model.layers[0].input], [model.layers[layer_num].output]) 
    f = layer([img])[0] 
    feature_aspect = math.ceil(math.sqrt(channel)) 
    single_size = int(input_size * ds)
    plt.figure(figsize=(8, 8.5)) 
    plt.suptitle('Layer-' + str(layer_num), fontsize=22)
    plt.subplots_adjust(left=0.02, bottom=0.02, right=0.98, top=0.94, wspace=0.05, hspace=0.05) 
    for i_channel in range(channel): 
        print('Channel-{} in Layer-{} is running.'.format(i_channel + 1, layer_num)) 
        show_img = f[:, :, :, i_channel] 
        show_img = np.reshape(show_img, (single_size, single_size)) 
        plt.subplot(feature_aspect, feature_aspect, i_channel + 1) 
        plt.imshow(show_img)  
        plt.axis('off') 
    fig = plt.gcf() 
    fig.savefig('data/instance/feature_kernel_images/layer_' + str(layer_num).zfill(2) + '.png', format='png', dpi=300)
    plt.show()
    
all_channels, down_sampling, conv_layers, conv_channels = network_configuration()
if layer_vis: 
    for i in range(len(all_channels)): 
        layer_visualization(model, img, i + 1, all_channels[i], down_sampling[i])

4. 采用预训练的Resnet实现猫狗识别

from tensorflow.keras.applications.resnet50 import ResNet50 
from tensorflow.keras.preprocessing import image 
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions 
import numpy as np 
from PIL import ImageFont, ImageDraw, Image 
import cv2
img_path = 'data\instance\dog.jpg'     #进行狗的判断
#img_path = 'cat.jpg'     #进行猫的判断
#img_path = 'deer.jpg'    #进行鹿的判断
weights_path = 'resnet50_weights.h5'
img = image.load_img(img_path, target_size=(224, 224)) 
x = image.img_to_array(img) 
x = np.expand_dims(x, axis=0) 
x = preprocess_input(x)
def get_model(): 
    model = ResNet50(weights=weights_path) 
    # 导入模型以及预训练权重
    print(model.summary()) # 打印模型概况 
    return model
model = get_model() 

Model: "resnet50"
__________________________________________________________________________________________________
 Layer (type)                   Output Shape         Param #     Connected to                     
==================================================================================================
 input_4 (InputLayer)           [(None, 224, 224, 3  0           []                               
                                )]                                                                
                                                                                                  
 conv1_pad (ZeroPadding2D)      (None, 230, 230, 3)  0           ['input_4[0][0]']                
                                                                                                  
 conv1_conv (Conv2D)            (None, 112, 112, 64  9472        ['conv1_pad[0][0]']              
                                )                                                                 
                                                                                                  
 conv1_bn (BatchNormalization)  (None, 112, 112, 64  256         ['conv1_conv[0][0]']             
                                )                                                                 
                                                                                                  
 conv1_relu (Activation)        (None, 112, 112, 64  0           ['conv1_bn[0][0]']               
                                )                                                                 
                                                                                                  
 pool1_pad (ZeroPadding2D)      (None, 114, 114, 64  0           ['conv1_relu[0][0]']             
                                )                                                                 
                                                                                                  
 pool1_pool (MaxPooling2D)      (None, 56, 56, 64)   0           ['pool1_pad[0][0]']              
                                                                                                  
 conv2_block1_1_conv (Conv2D)   (None, 56, 56, 64)   4160        ['pool1_pool[0][0]']             
                                                                                                  
 conv2_block1_1_bn (BatchNormal  (None, 56, 56, 64)  256         ['conv2_block1_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv2_block1_1_relu (Activatio  (None, 56, 56, 64)  0           ['conv2_block1_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv2_block1_2_conv (Conv2D)   (None, 56, 56, 64)   36928       ['conv2_block1_1_relu[0][0]']    
                                                                                                  
 conv2_block1_2_bn (BatchNormal  (None, 56, 56, 64)  256         ['conv2_block1_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv2_block1_2_relu (Activatio  (None, 56, 56, 64)  0           ['conv2_block1_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv2_block1_0_conv (Conv2D)   (None, 56, 56, 256)  16640       ['pool1_pool[0][0]']             
                                                                                                  
 conv2_block1_3_conv (Conv2D)   (None, 56, 56, 256)  16640       ['conv2_block1_2_relu[0][0]']    
                                                                                                  
 conv2_block1_0_bn (BatchNormal  (None, 56, 56, 256)  1024       ['conv2_block1_0_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv2_block1_3_bn (BatchNormal  (None, 56, 56, 256)  1024       ['conv2_block1_3_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv2_block1_add (Add)         (None, 56, 56, 256)  0           ['conv2_block1_0_bn[0][0]',      
                                                                  'conv2_block1_3_bn[0][0]']      
                                                                                                  
 conv2_block1_out (Activation)  (None, 56, 56, 256)  0           ['conv2_block1_add[0][0]']       
                                                                                                  
 conv2_block2_1_conv (Conv2D)   (None, 56, 56, 64)   16448       ['conv2_block1_out[0][0]']       
                                                                                                  
 conv2_block2_1_bn (BatchNormal  (None, 56, 56, 64)  256         ['conv2_block2_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv2_block2_1_relu (Activatio  (None, 56, 56, 64)  0           ['conv2_block2_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv2_block2_2_conv (Conv2D)   (None, 56, 56, 64)   36928       ['conv2_block2_1_relu[0][0]']    
                                                                                                  
 conv2_block2_2_bn (BatchNormal  (None, 56, 56, 64)  256         ['conv2_block2_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv2_block2_2_relu (Activatio  (None, 56, 56, 64)  0           ['conv2_block2_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv2_block2_3_conv (Conv2D)   (None, 56, 56, 256)  16640       ['conv2_block2_2_relu[0][0]']    
                                                                                                  
 conv2_block2_3_bn (BatchNormal  (None, 56, 56, 256)  1024       ['conv2_block2_3_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv2_block2_add (Add)         (None, 56, 56, 256)  0           ['conv2_block1_out[0][0]',       
                                                                  'conv2_block2_3_bn[0][0]']      
                                                                                                  
 conv2_block2_out (Activation)  (None, 56, 56, 256)  0           ['conv2_block2_add[0][0]']       
                                                                                                  
 conv2_block3_1_conv (Conv2D)   (None, 56, 56, 64)   16448       ['conv2_block2_out[0][0]']       
                                                                                                  
 conv2_block3_1_bn (BatchNormal  (None, 56, 56, 64)  256         ['conv2_block3_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv2_block3_1_relu (Activatio  (None, 56, 56, 64)  0           ['conv2_block3_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv2_block3_2_conv (Conv2D)   (None, 56, 56, 64)   36928       ['conv2_block3_1_relu[0][0]']    
                                                                                                  
 conv2_block3_2_bn (BatchNormal  (None, 56, 56, 64)  256         ['conv2_block3_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv2_block3_2_relu (Activatio  (None, 56, 56, 64)  0           ['conv2_block3_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv2_block3_3_conv (Conv2D)   (None, 56, 56, 256)  16640       ['conv2_block3_2_relu[0][0]']    
                                                                                                  
 conv2_block3_3_bn (BatchNormal  (None, 56, 56, 256)  1024       ['conv2_block3_3_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv2_block3_add (Add)         (None, 56, 56, 256)  0           ['conv2_block2_out[0][0]',       
                                                                  'conv2_block3_3_bn[0][0]']      
                                                                                                  
 conv2_block3_out (Activation)  (None, 56, 56, 256)  0           ['conv2_block3_add[0][0]']       
                                                                                                  
 conv3_block1_1_conv (Conv2D)   (None, 28, 28, 128)  32896       ['conv2_block3_out[0][0]']       
                                                                                                  
 conv3_block1_1_bn (BatchNormal  (None, 28, 28, 128)  512        ['conv3_block1_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block1_1_relu (Activatio  (None, 28, 28, 128)  0          ['conv3_block1_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv3_block1_2_conv (Conv2D)   (None, 28, 28, 128)  147584      ['conv3_block1_1_relu[0][0]']    
                                                                                                  
 conv3_block1_2_bn (BatchNormal  (None, 28, 28, 128)  512        ['conv3_block1_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block1_2_relu (Activatio  (None, 28, 28, 128)  0          ['conv3_block1_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv3_block1_0_conv (Conv2D)   (None, 28, 28, 512)  131584      ['conv2_block3_out[0][0]']       
                                                                                                  
 conv3_block1_3_conv (Conv2D)   (None, 28, 28, 512)  66048       ['conv3_block1_2_relu[0][0]']    
                                                                                                  
 conv3_block1_0_bn (BatchNormal  (None, 28, 28, 512)  2048       ['conv3_block1_0_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block1_3_bn (BatchNormal  (None, 28, 28, 512)  2048       ['conv3_block1_3_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block1_add (Add)         (None, 28, 28, 512)  0           ['conv3_block1_0_bn[0][0]',      
                                                                  'conv3_block1_3_bn[0][0]']      
                                                                                                  
 conv3_block1_out (Activation)  (None, 28, 28, 512)  0           ['conv3_block1_add[0][0]']       
                                                                                                  
 conv3_block2_1_conv (Conv2D)   (None, 28, 28, 128)  65664       ['conv3_block1_out[0][0]']       
                                                                                                  
 conv3_block2_1_bn (BatchNormal  (None, 28, 28, 128)  512        ['conv3_block2_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block2_1_relu (Activatio  (None, 28, 28, 128)  0          ['conv3_block2_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv3_block2_2_conv (Conv2D)   (None, 28, 28, 128)  147584      ['conv3_block2_1_relu[0][0]']    
                                                                                                  
 conv3_block2_2_bn (BatchNormal  (None, 28, 28, 128)  512        ['conv3_block2_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block2_2_relu (Activatio  (None, 28, 28, 128)  0          ['conv3_block2_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv3_block2_3_conv (Conv2D)   (None, 28, 28, 512)  66048       ['conv3_block2_2_relu[0][0]']    
                                                                                                  
 conv3_block2_3_bn (BatchNormal  (None, 28, 28, 512)  2048       ['conv3_block2_3_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block2_add (Add)         (None, 28, 28, 512)  0           ['conv3_block1_out[0][0]',       
                                                                  'conv3_block2_3_bn[0][0]']      
                                                                                                  
 conv3_block2_out (Activation)  (None, 28, 28, 512)  0           ['conv3_block2_add[0][0]']       
                                                                                                  
 conv3_block3_1_conv (Conv2D)   (None, 28, 28, 128)  65664       ['conv3_block2_out[0][0]']       
                                                                                                  
 conv3_block3_1_bn (BatchNormal  (None, 28, 28, 128)  512        ['conv3_block3_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block3_1_relu (Activatio  (None, 28, 28, 128)  0          ['conv3_block3_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv3_block3_2_conv (Conv2D)   (None, 28, 28, 128)  147584      ['conv3_block3_1_relu[0][0]']    
                                                                                                  
 conv3_block3_2_bn (BatchNormal  (None, 28, 28, 128)  512        ['conv3_block3_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block3_2_relu (Activatio  (None, 28, 28, 128)  0          ['conv3_block3_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv3_block3_3_conv (Conv2D)   (None, 28, 28, 512)  66048       ['conv3_block3_2_relu[0][0]']    
                                                                                                  
 conv3_block3_3_bn (BatchNormal  (None, 28, 28, 512)  2048       ['conv3_block3_3_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block3_add (Add)         (None, 28, 28, 512)  0           ['conv3_block2_out[0][0]',       
                                                                  'conv3_block3_3_bn[0][0]']      
                                                                                                  
 conv3_block3_out (Activation)  (None, 28, 28, 512)  0           ['conv3_block3_add[0][0]']       
                                                                                                  
 conv3_block4_1_conv (Conv2D)   (None, 28, 28, 128)  65664       ['conv3_block3_out[0][0]']       
                                                                                                  
 conv3_block4_1_bn (BatchNormal  (None, 28, 28, 128)  512        ['conv3_block4_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block4_1_relu (Activatio  (None, 28, 28, 128)  0          ['conv3_block4_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv3_block4_2_conv (Conv2D)   (None, 28, 28, 128)  147584      ['conv3_block4_1_relu[0][0]']    
                                                                                                  
 conv3_block4_2_bn (BatchNormal  (None, 28, 28, 128)  512        ['conv3_block4_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block4_2_relu (Activatio  (None, 28, 28, 128)  0          ['conv3_block4_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv3_block4_3_conv (Conv2D)   (None, 28, 28, 512)  66048       ['conv3_block4_2_relu[0][0]']    
                                                                                                  
 conv3_block4_3_bn (BatchNormal  (None, 28, 28, 512)  2048       ['conv3_block4_3_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv3_block4_add (Add)         (None, 28, 28, 512)  0           ['conv3_block3_out[0][0]',       
                                                                  'conv3_block4_3_bn[0][0]']      
                                                                                                  
 conv3_block4_out (Activation)  (None, 28, 28, 512)  0           ['conv3_block4_add[0][0]']       
                                                                                                  
 conv4_block1_1_conv (Conv2D)   (None, 14, 14, 256)  131328      ['conv3_block4_out[0][0]']       
                                                                                                  
 conv4_block1_1_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block1_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block1_1_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block1_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block1_2_conv (Conv2D)   (None, 14, 14, 256)  590080      ['conv4_block1_1_relu[0][0]']    
                                                                                                  
 conv4_block1_2_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block1_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block1_2_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block1_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block1_0_conv (Conv2D)   (None, 14, 14, 1024  525312      ['conv3_block4_out[0][0]']       
                                )                                                                 
                                                                                                  
 conv4_block1_3_conv (Conv2D)   (None, 14, 14, 1024  263168      ['conv4_block1_2_relu[0][0]']    
                                )                                                                 
                                                                                                  
 conv4_block1_0_bn (BatchNormal  (None, 14, 14, 1024  4096       ['conv4_block1_0_conv[0][0]']    
 ization)                       )                                                                 
                                                                                                  
 conv4_block1_3_bn (BatchNormal  (None, 14, 14, 1024  4096       ['conv4_block1_3_conv[0][0]']    
 ization)                       )                                                                 
                                                                                                  
 conv4_block1_add (Add)         (None, 14, 14, 1024  0           ['conv4_block1_0_bn[0][0]',      
                                )                                 'conv4_block1_3_bn[0][0]']      
                                                                                                  
 conv4_block1_out (Activation)  (None, 14, 14, 1024  0           ['conv4_block1_add[0][0]']       
                                )                                                                 
                                                                                                  
 conv4_block2_1_conv (Conv2D)   (None, 14, 14, 256)  262400      ['conv4_block1_out[0][0]']       
                                                                                                  
 conv4_block2_1_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block2_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block2_1_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block2_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block2_2_conv (Conv2D)   (None, 14, 14, 256)  590080      ['conv4_block2_1_relu[0][0]']    
                                                                                                  
 conv4_block2_2_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block2_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block2_2_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block2_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block2_3_conv (Conv2D)   (None, 14, 14, 1024  263168      ['conv4_block2_2_relu[0][0]']    
                                )                                                                 
                                                                                                  
 conv4_block2_3_bn (BatchNormal  (None, 14, 14, 1024  4096       ['conv4_block2_3_conv[0][0]']    
 ization)                       )                                                                 
                                                                                                  
 conv4_block2_add (Add)         (None, 14, 14, 1024  0           ['conv4_block1_out[0][0]',       
                                )                                 'conv4_block2_3_bn[0][0]']      
                                                                                                  
 conv4_block2_out (Activation)  (None, 14, 14, 1024  0           ['conv4_block2_add[0][0]']       
                                )                                                                 
                                                                                                  
 conv4_block3_1_conv (Conv2D)   (None, 14, 14, 256)  262400      ['conv4_block2_out[0][0]']       
                                                                                                  
 conv4_block3_1_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block3_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block3_1_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block3_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block3_2_conv (Conv2D)   (None, 14, 14, 256)  590080      ['conv4_block3_1_relu[0][0]']    
                                                                                                  
 conv4_block3_2_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block3_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block3_2_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block3_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block3_3_conv (Conv2D)   (None, 14, 14, 1024  263168      ['conv4_block3_2_relu[0][0]']    
                                )                                                                 
                                                                                                  
 conv4_block3_3_bn (BatchNormal  (None, 14, 14, 1024  4096       ['conv4_block3_3_conv[0][0]']    
 ization)                       )                                                                 
                                                                                                  
 conv4_block3_add (Add)         (None, 14, 14, 1024  0           ['conv4_block2_out[0][0]',       
                                )                                 'conv4_block3_3_bn[0][0]']      
                                                                                                  
 conv4_block3_out (Activation)  (None, 14, 14, 1024  0           ['conv4_block3_add[0][0]']       
                                )                                                                 
                                                                                                  
 conv4_block4_1_conv (Conv2D)   (None, 14, 14, 256)  262400      ['conv4_block3_out[0][0]']       
                                                                                                  
 conv4_block4_1_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block4_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block4_1_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block4_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block4_2_conv (Conv2D)   (None, 14, 14, 256)  590080      ['conv4_block4_1_relu[0][0]']    
                                                                                                  
 conv4_block4_2_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block4_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block4_2_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block4_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block4_3_conv (Conv2D)   (None, 14, 14, 1024  263168      ['conv4_block4_2_relu[0][0]']    
                                )                                                                 
                                                                                                  
 conv4_block4_3_bn (BatchNormal  (None, 14, 14, 1024  4096       ['conv4_block4_3_conv[0][0]']    
 ization)                       )                                                                 
                                                                                                  
 conv4_block4_add (Add)         (None, 14, 14, 1024  0           ['conv4_block3_out[0][0]',       
                                )                                 'conv4_block4_3_bn[0][0]']      
                                                                                                  
 conv4_block4_out (Activation)  (None, 14, 14, 1024  0           ['conv4_block4_add[0][0]']       
                                )                                                                 
                                                                                                  
 conv4_block5_1_conv (Conv2D)   (None, 14, 14, 256)  262400      ['conv4_block4_out[0][0]']       
                                                                                                  
 conv4_block5_1_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block5_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block5_1_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block5_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block5_2_conv (Conv2D)   (None, 14, 14, 256)  590080      ['conv4_block5_1_relu[0][0]']    
                                                                                                  
 conv4_block5_2_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block5_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block5_2_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block5_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block5_3_conv (Conv2D)   (None, 14, 14, 1024  263168      ['conv4_block5_2_relu[0][0]']    
                                )                                                                 
                                                                                                  
 conv4_block5_3_bn (BatchNormal  (None, 14, 14, 1024  4096       ['conv4_block5_3_conv[0][0]']    
 ization)                       )                                                                 
                                                                                                  
 conv4_block5_add (Add)         (None, 14, 14, 1024  0           ['conv4_block4_out[0][0]',       
                                )                                 'conv4_block5_3_bn[0][0]']      
                                                                                                  
 conv4_block5_out (Activation)  (None, 14, 14, 1024  0           ['conv4_block5_add[0][0]']       
                                )                                                                 
                                                                                                  
 conv4_block6_1_conv (Conv2D)   (None, 14, 14, 256)  262400      ['conv4_block5_out[0][0]']       
                                                                                                  
 conv4_block6_1_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block6_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block6_1_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block6_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block6_2_conv (Conv2D)   (None, 14, 14, 256)  590080      ['conv4_block6_1_relu[0][0]']    
                                                                                                  
 conv4_block6_2_bn (BatchNormal  (None, 14, 14, 256)  1024       ['conv4_block6_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv4_block6_2_relu (Activatio  (None, 14, 14, 256)  0          ['conv4_block6_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv4_block6_3_conv (Conv2D)   (None, 14, 14, 1024  263168      ['conv4_block6_2_relu[0][0]']    
                                )                                                                 
                                                                                                  
 conv4_block6_3_bn (BatchNormal  (None, 14, 14, 1024  4096       ['conv4_block6_3_conv[0][0]']    
 ization)                       )                                                                 
                                                                                                  
 conv4_block6_add (Add)         (None, 14, 14, 1024  0           ['conv4_block5_out[0][0]',       
                                )                                 'conv4_block6_3_bn[0][0]']      
                                                                                                  
 conv4_block6_out (Activation)  (None, 14, 14, 1024  0           ['conv4_block6_add[0][0]']       
                                )                                                                 
                                                                                                  
 conv5_block1_1_conv (Conv2D)   (None, 7, 7, 512)    524800      ['conv4_block6_out[0][0]']       
                                                                                                  
 conv5_block1_1_bn (BatchNormal  (None, 7, 7, 512)   2048        ['conv5_block1_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv5_block1_1_relu (Activatio  (None, 7, 7, 512)   0           ['conv5_block1_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv5_block1_2_conv (Conv2D)   (None, 7, 7, 512)    2359808     ['conv5_block1_1_relu[0][0]']    
                                                                                                  
 conv5_block1_2_bn (BatchNormal  (None, 7, 7, 512)   2048        ['conv5_block1_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv5_block1_2_relu (Activatio  (None, 7, 7, 512)   0           ['conv5_block1_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv5_block1_0_conv (Conv2D)   (None, 7, 7, 2048)   2099200     ['conv4_block6_out[0][0]']       
                                                                                                  
 conv5_block1_3_conv (Conv2D)   (None, 7, 7, 2048)   1050624     ['conv5_block1_2_relu[0][0]']    
                                                                                                  
 conv5_block1_0_bn (BatchNormal  (None, 7, 7, 2048)  8192        ['conv5_block1_0_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv5_block1_3_bn (BatchNormal  (None, 7, 7, 2048)  8192        ['conv5_block1_3_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv5_block1_add (Add)         (None, 7, 7, 2048)   0           ['conv5_block1_0_bn[0][0]',      
                                                                  'conv5_block1_3_bn[0][0]']      
                                                                                                  
 conv5_block1_out (Activation)  (None, 7, 7, 2048)   0           ['conv5_block1_add[0][0]']       
                                                                                                  
 conv5_block2_1_conv (Conv2D)   (None, 7, 7, 512)    1049088     ['conv5_block1_out[0][0]']       
                                                                                                  
 conv5_block2_1_bn (BatchNormal  (None, 7, 7, 512)   2048        ['conv5_block2_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv5_block2_1_relu (Activatio  (None, 7, 7, 512)   0           ['conv5_block2_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv5_block2_2_conv (Conv2D)   (None, 7, 7, 512)    2359808     ['conv5_block2_1_relu[0][0]']    
                                                                                                  
 conv5_block2_2_bn (BatchNormal  (None, 7, 7, 512)   2048        ['conv5_block2_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv5_block2_2_relu (Activatio  (None, 7, 7, 512)   0           ['conv5_block2_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv5_block2_3_conv (Conv2D)   (None, 7, 7, 2048)   1050624     ['conv5_block2_2_relu[0][0]']    
                                                                                                  
 conv5_block2_3_bn (BatchNormal  (None, 7, 7, 2048)  8192        ['conv5_block2_3_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv5_block2_add (Add)         (None, 7, 7, 2048)   0           ['conv5_block1_out[0][0]',       
                                                                  'conv5_block2_3_bn[0][0]']      
                                                                                                  
 conv5_block2_out (Activation)  (None, 7, 7, 2048)   0           ['conv5_block2_add[0][0]']       
                                                                                                  
 conv5_block3_1_conv (Conv2D)   (None, 7, 7, 512)    1049088     ['conv5_block2_out[0][0]']       
                                                                                                  
 conv5_block3_1_bn (BatchNormal  (None, 7, 7, 512)   2048        ['conv5_block3_1_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv5_block3_1_relu (Activatio  (None, 7, 7, 512)   0           ['conv5_block3_1_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv5_block3_2_conv (Conv2D)   (None, 7, 7, 512)    2359808     ['conv5_block3_1_relu[0][0]']    
                                                                                                  
 conv5_block3_2_bn (BatchNormal  (None, 7, 7, 512)   2048        ['conv5_block3_2_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv5_block3_2_relu (Activatio  (None, 7, 7, 512)   0           ['conv5_block3_2_bn[0][0]']      
 n)                                                                                               
                                                                                                  
 conv5_block3_3_conv (Conv2D)   (None, 7, 7, 2048)   1050624     ['conv5_block3_2_relu[0][0]']    
                                                                                                  
 conv5_block3_3_bn (BatchNormal  (None, 7, 7, 2048)  8192        ['conv5_block3_3_conv[0][0]']    
 ization)                                                                                         
                                                                                                  
 conv5_block3_add (Add)         (None, 7, 7, 2048)   0           ['conv5_block2_out[0][0]',       
                                                                  'conv5_block3_3_bn[0][0]']      
                                                                                                  
 conv5_block3_out (Activation)  (None, 7, 7, 2048)   0           ['conv5_block3_add[0][0]']       
                                                                                                  
 avg_pool (GlobalAveragePooling  (None, 2048)        0           ['conv5_block3_out[0][0]']       
 2D)                                                                                              
                                                                                                  
 predictions (Dense)            (None, 1000)         2049000     ['avg_pool[0][0]']               
                                                                                                  
==================================================================================================
Total params: 25,636,712
Trainable params: 25,583,592
Non-trainable params: 53,120
__________________________________________________________________________________________________
None
preds = model.predict(x)
1/1 [==============================] - 1s 854ms/step
print('Predicted:', decode_predictions(preds, top=5)[0])
Predicted: [('n02108422', 'bull_mastiff', 0.3921146), ('n02110958', 'pug', 0.2944119), ('n02093754', 'Border_terrier', 0.14356579), ('n02108915', 'French_bulldog', 0.057976846), ('n02099712', 'Labrador_retriever', 0.052499186)]

TensorFlow2.2基本应用

import tensorflow as tf
x=tf.random.normal([2,16])
w1=tf.Variable(tf.random.truncated_normal([16,8],stddev=0.1))
b1=tf.Variable(tf.zeros([8]))
o1=tf.matmul(x,w1)+b1
o1=tf.nn.relu(o1)
o1

<tf.Tensor: id=8263, shape=(2, 8), dtype=float32, numpy=
array([[0.16938789, 0. , 0.08883161, 0.14095941, 0.34751543,
0.353898 , 0. , 0.13356908],
[0. , 0. , 0.48546872, 0.37623546, 0.5447475 ,
0.21755993, 0.40121362, 0. ]], dtype=float32)>

from tensorflow.keras import layers
x=tf.random.normal([4,16*16])
fc=layers.Dense(5,activation=tf.nn.relu)
h1=fc(x)
h1

<tf.Tensor: id=8296, shape=(4, 5), dtype=float32, numpy=
array([[0. , 0. , 0. , 0.14286758, 0. ],
[0. , 2.2727172 , 0. , 0. , 0.34961763],
[0.1311972 , 0. , 1.4005635 , 0. , 0. ],
[0. , 1.7266206 , 0.64711714, 1.3494569 , 0. ]],
dtype=float32)>

#获取权值矩阵w
fc.kernel

<tf.Variable ‘dense/kernel:0’ shape=(256, 5) dtype=float32, numpy=
array([[-0.0339304 , 0.02273461, -0.12746884, 0.14963049, 0.00773269],
[-0.05978647, 0.07886668, -0.09110804, 0.14902723, 0.13007113],
[ 0.10187459, 0.13089484, 0.14367685, 0.12212327, -0.06235344],
…,
[ 0.10417426, 0.05112691, 0.12206474, 0.01141772, -0.05271714],
[ 0.03493455, -0.13473712, -0.01317982, -0.09485313, 0.04731715],
[ 0.12421742, 0.00030141, -0.00211757, -0.04196439, -0.03638943]],
dtype=float32)>

fc.bias

<tf.Variable ‘dense/bias:0’ shape=(5,) dtype=float32, numpy=array([0., 0., 0., 0., 0.], dtype=float32)>

fc.trainable_variables

[<tf.Variable ‘dense/kernel:0’ shape=(256, 5) dtype=float32, numpy=
array([[-0.0339304 , 0.02273461, -0.12746884, 0.14963049, 0.00773269],
[-0.05978647, 0.07886668, -0.09110804, 0.14902723, 0.13007113],
[ 0.10187459, 0.13089484, 0.14367685, 0.12212327, -0.06235344],
…,
[ 0.10417426, 0.05112691, 0.12206474, 0.01141772, -0.05271714],
[ 0.03493455, -0.13473712, -0.01317982, -0.09485313, 0.04731715],
[ 0.12421742, 0.00030141, -0.00211757, -0.04196439, -0.03638943]],
dtype=float32)>,
<tf.Variable ‘dense/bias:0’ shape=(5,) dtype=float32, numpy=array([0., 0., 0., 0., 0.], dtype=float32)>]

fc.variables

[<tf.Variable ‘dense/kernel:0’ shape=(256, 5) dtype=float32, numpy=
array([[-0.0339304 , 0.02273461, -0.12746884, 0.14963049, 0.00773269],
[-0.05978647, 0.07886668, -0.09110804, 0.14902723, 0.13007113],
[ 0.10187459, 0.13089484, 0.14367685, 0.12212327, -0.06235344],
…,
[ 0.10417426, 0.05112691, 0.12206474, 0.01141772, -0.05271714],
[ 0.03493455, -0.13473712, -0.01317982, -0.09485313, 0.04731715],
[ 0.12421742, 0.00030141, -0.00211757, -0.04196439, -0.03638943]],
dtype=float32)>,
<tf.Variable ‘dense/bias:0’ shape=(5,) dtype=float32, numpy=array([0., 0., 0., 0., 0.], dtype=float32)>]

5. 使用深度学习进行手写数字识别

import tensorflow as tf

#载入MNIST 数据集。
mnist = tf.keras.datasets.mnist
#拆分数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()
#将样本进行预处理,并从整数转换为浮点数
x_train, x_test = x_train / 255.0, x_test / 255.0

#使用tf.keras.Sequential将模型的各层堆叠,并设置参数
model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation='softmax')
])
#设置模型的优化器和损失函数
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
#训练并验证模型
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test,  y_test, verbose=2)
Train on 60000 samples
Epoch 1/5
60000/60000 [==============================] - 6s 95us/sample - loss: 0.2931 - accuracy: 0.9146
Epoch 2/5
60000/60000 [==============================] - 5s 77us/sample - loss: 0.1419 - accuracy: 0.9592
Epoch 3/5
60000/60000 [==============================] - 5s 78us/sample - loss: 0.1065 - accuracy: 0.9683
Epoch 4/5
60000/60000 [==============================] - 5s 78us/sample - loss: 0.0852 - accuracy: 0.9738
Epoch 5/5
60000/60000 [==============================] - 6s 100us/sample - loss: 0.0735 - accuracy: 0.9769
10000/1 - 0s - loss: 0.0338 - accuracy: 0.9795
[0.0666636555833742, 0.9795]

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

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

相关文章

AMBA总线协议(7)——AHB(五):传输仲裁

一、前言 在之前的文章中我们讨论了AHB的很多传输细节&#xff0c;主要有控制信号&#xff0c;地址信号的译码&#xff0c;从机的响应等&#xff0c;其中重点介绍了双周期响应&#xff0c;最后介绍了数据总线及端结构&#xff0c;在本文中我们将继续介绍AHB传输的仲裁机制。 仲…

利用大模型反馈故障的解决方案

背景 观测云有两个错误巡检脚本&#xff0c;RUM 错误巡检和 APM 错误巡检&#xff0c;代码均开源。 错误巡检的主要目的是发现新出现的错误消息(error stack)&#xff0c;原有的巡检在上报了相应的事件报告后&#xff0c;只是定位了问题&#xff0c;并没有给出合适的解决方案。…

数据分析实战│价格预测挑战【文末赠书】

文本分析是指对文本信息的表示及特征项的选取&#xff0c;商品文本的描述能够反映特定立场、观点、价值和利益。考虑到网上海量的商品数量&#xff0c;对产品的定价难度很大&#xff0c;因此可以使用商品描述帮助商户定价。比如&#xff0c;服装具有较强的季节性价格趋势&#…

PHP 创业感悟交流平台系统mysql数据库web结构apache计算机软件工程网页wamp

一、源码特点 PHP 创业感悟交流平台系统&#xff08;含论坛&#xff09;是一套完善的web设计系统&#xff0c;对理解php编程开发语言有帮助&#xff0c;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。 源码下载&#xff1a; https://download.csdn.…

C++中cin >> str 和 string类的getline(cin, str) 用来读取用户输入的两种不同方式的不同点

C中cin >> str 和 string类的getline(cin, str) 用来读取用户输入的两种不同方式的不同点 在C中&#xff0c;string类是标准库提供的字符串类&#xff0c;它可以帮助我们处理和操作字符串。它在<string>头文件中定义。string类提供了一系列成员函数和操作符&#…

Numpy入门(5)—应用举例

NumPy应用举例 5.1 计算激活函数Sigmoid和ReLU 使用ndarray数组可以很方便的构建数学函数&#xff0c;并利用其底层的矢量计算能力快速实现计算。下面以神经网络中比较常用激活函数Sigmoid和ReLU为例&#xff0c;介绍代码实现过程。 计算Sigmoid激活函数 计算ReLU激活函数 使…

C++ vector模拟实现

建议将vector的模拟实现写在头文件中&#xff0c;测试使用部分写在.cpp文件中 vector是类模板&#xff0c;被封装在命名空间中 部分源码&#xff1a;&#xff08;删除某些内容后&#xff09; vector模拟实现的代码&#xff1a; #include<assert.h> namespace djx {tem…

【Git分支操作---讲解二】

Git分支操作---讲解二 查看分支创建分支切换分支修改分支切换分支合并分支合并分支【冲突】(只会修改主分支不会修改其他分支)什么时候会有冲突&#xff1f; 查看分支 创建分支 切换分支 修改分支 切换分支 合并分支 合并分支【冲突】(只会修改主分支不会修改其他分支) 什么时…

国产精品:讯飞星火最新大模型V2.0

大家好&#xff0c;我是爱编程的喵喵。双985硕士毕业&#xff0c;现担任全栈工程师一职&#xff0c;热衷于将数据思维应用到工作与生活中。从事机器学习以及相关的前后端开发工作。曾在阿里云、科大讯飞、CCF等比赛获得多次Top名次。现为CSDN博客专家、人工智能领域优质创作者。…

FL Studio2023最新版本21.1中文水果音乐编曲工具

虚拟乐器和真实乐器的区别&#xff1f;真实乐器指的是现实中需要乐手演奏的乐器&#xff0c;而虚拟乐器是计算机音乐制作中编曲师使用的数字乐器。FL Studio虚拟乐器插件有哪些&#xff1f;下文将给大家介绍几款FL Studio自带的强大虚拟乐器。 一、虚拟乐器和真实乐器的区别 …

JDK21真的来了:虚拟线程正式发布及十多项新特性!

点击下方“JavaEdge”&#xff0c;选择“设为星标” 第一时间关注技术干货&#xff01; 免责声明~ 任何文章不要过度深思&#xff01; 万事万物都经不起审视&#xff0c;因为世上没有同样的成长环境&#xff0c;也没有同样的认知水平&#xff0c;更「没有适用于所有人的解决方案…

Docker容器与虚拟化技术:Docker-Compose单机编排工具

目录 一、理论 1.Docker-Compose 二、实验 1. Docker Compose 安装部署 2.Docker Compose撰写nginx 镜像 3.Docker Compose撰写tomcat 镜像 三、问题 1.Docker Compose 和 Dockerfile 的区别 四、总结 一、理论 1.Docker-Compose &#xff08;1&#xff09;使用场景…

渗透率超90%!智能座舱赛道迎来「存量」替代升级大周期

智能座舱赛道&#xff0c;正在迎来新一轮芯片替代潮。 相比于智能驾驶领域&#xff0c;座舱主机芯片市场并不「性感」&#xff0c;但巨大的存量替代升级机会&#xff0c;也不容小视。 高工智能汽车研究院监测数据显示&#xff0c;2023年1-6月中国市场&#xff08;不含进出口&am…

通用语言模型蒸馏-GLMD

文章目录 GLMD一、PPT内容论文背景P1 BackgroundP2 Approach 相关知识P3 知识蒸馏P4 语言建模词预测逻辑 方法P5 两阶段词汇预测蒸馏P6P7 词汇压缩 实验结果P8 results 二、论文泛读2.1 论文要解决什么问题&#xff1f;2.2 论文采用了什么方法&#xff1f;2.4 论文达到什么效果…

C++学习笔记---- 引用

1、作用 给变量起别名 基本语法&#xff1a;数据类型 &别名 原名 示例&#xff1a; #include <iostream> using namespace std;int main() {int a 1;int &b a;cout << "a " << a << endl;cout << "b " <…

关于Map的理解

Shuffle中进行了分组聚合,而Reduce对分组聚合后的数据进行重新计算. 切片对应的是MapTask 分区对应的是ReduceTask 也可以通过设定reduce数量来调整分区数 分区规则: 设定为1时, 根本不走自定义分区器,而是Hash 如果分区数大于规则 空 如果分区数小于规则(分区数不为1) 报错 …

《金字塔原理》(表达的逻辑)

前言&#xff1a;在思考和表达上&#xff0c;很多时候显得很混乱&#xff0c;源于不了解结构化思想、表达&#xff0c;如何让话讲得更有逻辑&#xff1f;事做得更有条理&#xff1f;接触到了一本书&#xff1a;《金字塔原理》&#xff0c;通过这本书的学习&#xff0c;希望可以…

数字化营销怎么做?数字化营销系统落地重点一览

如何抓住数字化机遇&#xff0c;企业取得营销突破&#xff1f;如果说数字是一种技术、工具或数据等无形的资源&#xff0c;那么数字化则代表了某种动态的过程、资源和能力&#xff0c;如同企业经营一样始终处于流动的过程之中。当前&#xff0c;由于科技水平的不断发展&#xf…

神经网络入门

前言 本文主要介绍最基础的神经网络&#xff0c;包括其结构&#xff0c;学习方法&#xff0c; C \texttt{C} C 的实现代码。 Python \texttt{Python} Python 的代码可以搜索互联网得到。 前排提示&#xff1a;本人涉及一丁点数学知识。 神经网络的结构 神经网络包括多个层…

【ARM】Day8 中断

1. 思维导图 2. 实验要求&#xff1a; 实现KEY1/LEY2/KE3三个按键&#xff0c;中断触发打印一句话&#xff0c;并且灯的状态取反 key1 ----> LED3灯状态取反 key2 ----> LED2灯状态取反 key3 ----> LED1灯状态取反 key3.h #ifndef __KEY3_H__ #define __KEY3_H__#in…