基于卷积神经网络的狗猫数据集分类实验

news2024/9/25 9:40:51

目录

    • 一、环境配置
      • 1、anaconda安装
      • 2、配置TensorFlow、Keras
    • 二、数据集分类
      • 1、分类源码
      • 2、训练流程
    • 三、模型调整
      • 1、图像增强
      • 2、网络模型添加dropout层
    • 四、使用VGG19优化提高猫狗图像分类
    • 五、总结
    • 六、参考资料

一、环境配置

1、anaconda安装

下载链接:anaconda
也可以看我前面博客的介绍:Windows下安装Anaconda3并使用Jupyter进行基础练习

2、配置TensorFlow、Keras

在这里插入图片描述
输入以下命令:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==1.14.0
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple keras==2.2.5

二、数据集分类

数据集链接:猫狗数据集
提取码:6688

1、分类源码

import os, shutil
# The path to the directory where the original
# dataset was uncompressed
original_dataset_dir = 'D:/dogcat/train/train'

# The directory where we will
# store our smaller dataset
base_dir = 'D:/dogcat/find_cats_and_dogs'
os.mkdir(base_dir)

# Directories for our training,
# validation and test splits
train_dir = os.path.join(base_dir, 'train')
os.mkdir(train_dir)
validation_dir = os.path.join(base_dir, 'validation')
os.mkdir(validation_dir)
test_dir = os.path.join(base_dir, 'test')
os.mkdir(test_dir)

# Directory with our training cat pictures
train_cats_dir = os.path.join(train_dir, 'cats')
os.mkdir(train_cats_dir)

# Directory with our training dog pictures
train_dogs_dir = os.path.join(train_dir, 'dogs')
os.mkdir(train_dogs_dir)

# Directory with our validation cat pictures
validation_cats_dir = os.path.join(validation_dir, 'cats')
os.mkdir(validation_cats_dir)

# Directory with our validation dog pictures
validation_dogs_dir = os.path.join(validation_dir, 'dogs')
os.mkdir(validation_dogs_dir)

# Directory with our validation cat pictures
test_cats_dir = os.path.join(test_dir, 'cats')
os.mkdir(test_cats_dir)

# Directory with our validation dog pictures
test_dogs_dir = os.path.join(test_dir, 'dogs')
os.mkdir(test_dogs_dir)

# Copy first 1000 cat images to train_cats_dir
fnames = ['cat.{}.jpg'.format(i) for i in range(1000)]
for fname in fnames:
    src = os.path.join(original_dataset_dir, fname)
    dst = os.path.join(train_cats_dir, fname)
    shutil.copyfile(src, dst)

# Copy next 500 cat images to validation_cats_dir
fnames = ['cat.{}.jpg'.format(i) for i in range(1000, 1500)]
for fname in fnames:
    src = os.path.join(original_dataset_dir, fname)
    dst = os.path.join(validation_cats_dir, fname)
    shutil.copyfile(src, dst)
    
# Copy next 500 cat images to test_cats_dir
fnames = ['cat.{}.jpg'.format(i) for i in range(1500, 2000)]
for fname in fnames:
    src = os.path.join(original_dataset_dir, fname)
    dst = os.path.join(test_cats_dir, fname)
    shutil.copyfile(src, dst)
    
# Copy first 1000 dog images to train_dogs_dir
fnames = ['dog.{}.jpg'.format(i) for i in range(1000)]
for fname in fnames:
    src = os.path.join(original_dataset_dir, fname)
    dst = os.path.join(train_dogs_dir, fname)
    shutil.copyfile(src, dst)
    
# Copy next 500 dog images to validation_dogs_dir
fnames = ['dog.{}.jpg'.format(i) for i in range(1000, 1500)]
for fname in fnames:
    src = os.path.join(original_dataset_dir, fname)
    dst = os.path.join(validation_dogs_dir, fname)
    shutil.copyfile(src, dst)
    
# Copy next 500 dog images to test_dogs_dir
fnames = ['dog.{}.jpg'.format(i) for i in range(1500, 2000)]
for fname in fnames:
    src = os.path.join(original_dataset_dir, fname)
    dst = os.path.join(test_dogs_dir, fname)
    shutil.copyfile(src, dst)

输出图片数量:

print('total training cat images:', len(os.listdir(train_cats_dir)))
print('total training dog images:', len(os.listdir(train_dogs_dir)))
print('total validation cat images:', len(os.listdir(validation_cats_dir)))
print('total validation dog images:', len(os.listdir(validation_dogs_dir)))
print('total test cat images:', len(os.listdir(test_cats_dir)))
print('total test dog images:', len(os.listdir(test_dogs_dir)))

如图:
在这里插入图片描述
分类后数据集分为测试、训练、验证集。猫狗训练图片各1000张,验证图片各500张,测试图片各500张。

2、训练流程

1、构建网络模型

#网络模型构建
from keras import layers
from keras import models
#keras的序贯模型
model = models.Sequential()
#卷积层,卷积核是3*3,激活函数relu
model.add(layers.Conv2D(32, (3, 3), activation='relu',
                        input_shape=(150, 150, 3)))
#最大池化层
model.add(layers.MaxPooling2D((2, 2)))
#卷积层,卷积核2*2,激活函数relu
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
#最大池化层
model.add(layers.MaxPooling2D((2, 2)))
#卷积层,卷积核是3*3,激活函数relu
model.add(layers.Conv2D(128, (3, 3), activation='relu'))
#最大池化层
model.add(layers.MaxPooling2D((2, 2)))
#卷积层,卷积核是3*3,激活函数relu
model.add(layers.Conv2D(128, (3, 3), activation='relu'))
#最大池化层
model.add(layers.MaxPooling2D((2, 2)))
#flatten层,用于将多维的输入一维化,用于卷积层和全连接层的过渡
model.add(layers.Flatten())
#全连接,激活函数relu
model.add(layers.Dense(512, activation='relu'))
#全连接,激活函数sigmoid
model.add(layers.Dense(1, activation='sigmoid'))

2、查看模型各参赛状态:

#输出模型各层的参数状况
model.summary()

如图:
在这里插入图片描述
3、对于编译步骤,我们将像往常一样使用RMSprop优化器。由于我们的网络是以一个单一的sigmoid单元结束的,所以我们将使用二元交叉矩阵作为我们的损失。

from keras import optimizers

model.compile(loss='binary_crossentropy',
              optimizer=optimizers.RMSprop(lr=1e-4),
              metrics=['acc'])

4、调整数据格式

from keras.preprocessing.image import ImageDataGenerator

# 所有图像将按1/255重新缩放
train_datagen = ImageDataGenerator(rescale=1./255)
test_datagen = ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory(
        # 这是目标目录
        train_dir,
        # 所有图像将调整为150x150
        target_size=(150, 150),
        batch_size=20,
        # 因为我们使用二元交叉熵损失,我们需要二元标签
        class_mode='binary')

validation_generator = test_datagen.flow_from_directory(
        validation_dir,
        target_size=(150, 150),
        batch_size=20,
        class_mode='binary')

如图:
在这里插入图片描述
5、查看生成器输出:

for data_batch, labels_batch in train_generator:
    print('data batch shape:', data_batch.shape)
    print('labels batch shape:', labels_batch.shape)
    break

如图:
在这里插入图片描述
6、使用生成器使我们的模型适合于数据并保存生成的模型:

#模型训练过程
history = model.fit_generator(
      train_generator,
      steps_per_epoch=100,
      epochs=30,
      validation_data=validation_generator,
      validation_steps=50)
#保存训练得到的的模型
model.save('D:\\dogcat\\cats_and_dogs_small_1.h5')

7、训练过程:
在这里插入图片描述
8、在训练和验证数据上绘制模型的损失和准确性:

import matplotlib.pyplot as plt
acc = history.history['acc']
val_acc = history.history['val_acc']
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(len(acc))
plt.plot(epochs, acc, 'bo', label='Training acc')
plt.plot(epochs, val_acc, 'b', label='Validation acc')
plt.title('Training and validation accuracy')
plt.legend()
plt.figure()
plt.plot(epochs, loss, 'bo', label='Training loss')
plt.plot(epochs, val_loss, 'b', label='Validation loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()

在这里插入图片描述
在这里插入图片描述

三、模型调整

1、图像增强

#该部分代码及以后的代码,用于替代基准模型中分类后面的代码(执行代码前,需要先将之前分类的目录删掉,重写生成分类,否则,会发生错误)
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(
      rotation_range=40,
      width_shift_range=0.2,
      height_shift_range=0.2,
      shear_range=0.2,
      zoom_range=0.2,
      horizontal_flip=True,
      fill_mode='nearest')

增强后的图像:

import matplotlib.pyplot as plt
# This is module with image preprocessing utilities
from keras.preprocessing import image
fnames = [os.path.join(train_cats_dir, fname) for fname in os.listdir(train_cats_dir)]
# We pick one image to "augment"
img_path = fnames[3]
# Read the image and resize it
img = image.load_img(img_path, target_size=(150, 150))
# Convert it to a Numpy array with shape (150, 150, 3)
x = image.img_to_array(img)
# Reshape it to (1, 150, 150, 3)
x = x.reshape((1,) + x.shape)
# The .flow() command below generates batches of randomly transformed images.
# It will loop indefinitely, so we need to `break` the loop at some point!
i = 0
for batch in datagen.flow(x, batch_size=1):
    plt.figure(i)
    imgplot = plt.imshow(image.array_to_img(batch[0]))
    i += 1
    if i % 4 == 0:
        break
plt.show()

如图:
在这里插入图片描述

2、网络模型添加dropout层

1、源码:

#网络模型构建
from keras import layers
from keras import models
#keras的序贯模型
model = models.Sequential()
#卷积层,卷积核是3*3,激活函数relu
model.add(layers.Conv2D(32, (3, 3), activation='relu',
                        input_shape=(150, 150, 3)))
#最大池化层
model.add(layers.MaxPooling2D((2, 2)))
#卷积层,卷积核2*2,激活函数relu
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
#最大池化层
model.add(layers.MaxPooling2D((2, 2)))
#卷积层,卷积核是3*3,激活函数relu
model.add(layers.Conv2D(128, (3, 3), activation='relu'))
#最大池化层
model.add(layers.MaxPooling2D((2, 2)))
#卷积层,卷积核是3*3,激活函数relu
model.add(layers.Conv2D(128, (3, 3), activation='relu'))
#最大池化层
model.add(layers.MaxPooling2D((2, 2)))
#flatten层,用于将多维的输入一维化,用于卷积层和全连接层的过渡
model.add(layers.Flatten())
#退出层
model.add(layers.Dropout(0.5))
#全连接,激活函数relu
model.add(layers.Dense(512, activation='relu'))
#全连接,激活函数sigmoid
model.add(layers.Dense(1, activation='sigmoid'))
#输出模型各层的参数状况
model.summary()
from keras import optimizers
model.compile(loss='binary_crossentropy',
              optimizer=optimizers.RMSprop(lr=1e-4),
              metrics=['acc'])

2、添加后的网络结构
在这里插入图片描述
3、模型训练

train_datagen = ImageDataGenerator(
    rescale=1./255,
    rotation_range=40,
    width_shift_range=0.2,
    height_shift_range=0.2,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True,)
# Note that the validation data should not be augmented!
test_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
        # This is the target directory
        train_dir,
        # All images will be resized to 150x150
        target_size=(150, 150),
        batch_size=32,
        # Since we use binary_crossentropy loss, we need binary labels
        class_mode='binary')
validation_generator = test_datagen.flow_from_directory(
        validation_dir,
        target_size=(150, 150),
        batch_size=32,
        class_mode='binary')
history = model.fit_generator(
      train_generator,
      steps_per_epoch=100,
      epochs=100,
      validation_data=validation_generator,
      validation_steps=50)
model.save('D:\\dogcat\\cats_and_dogs_small_2.h5')

4、只进行数据增强的训练效果
在这里插入图片描述
5、数据增强和添加dropout层的训练效果
在这里插入图片描述
6、训练效果

acc = history.history['acc']
val_acc = history.history['val_acc']
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(len(acc))
plt.plot(epochs, acc, 'bo', label='Training acc')
plt.plot(epochs, val_acc, 'b', label='Validation acc')
plt.title('Training and validation accuracy')
plt.legend()
plt.figure()
plt.plot(epochs, loss, 'bo', label='Training loss')
plt.plot(epochs, val_loss, 'b', label='Validation loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()

7、只进行数据增强的情况
在这里插入图片描述
在这里插入图片描述
8、数据增强和添加dropout层的训练效果
在这里插入图片描述
在这里插入图片描述

四、使用VGG19优化提高猫狗图像分类

1、构建网络模型

from keras import layers
from keras import models
from keras import optimizers
model = models.Sequential()
#输入图片大小是150*150 3表示图片像素用(R,G,B)表示
model.add(layers.Conv2D(32, (3,3), activation='relu', input_shape=(150 , 150, 3)))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Conv2D(64, (3,3), activation='relu'))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Conv2D(128, (3,3), activation='relu'))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Conv2D(128, (3,3), activation='relu'))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Flatten())
model.add(layers.Dense(512, activation='relu'))
model.add(layers.Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer=optimizers.RMSprop(lr=1e-4),
             metrics=['acc'])
model.summary()

在这里插入图片描述
2、初始化一个VGG19网络实例

from keras.applications import VGG19
conv_base = VGG19(weights = 'imagenet',include_top = False,input_shape=(150, 150, 3))
conv_base.summary()

首次运行时候,会自动从对应网站下载h5格式文件,上面下载很慢,而且还有可能在中途挂掉,因此建议将网址复制到浏览器上,直接下载。然后,将下载的文件,放到对应的目录下。

模型网络结构如图:
在这里插入图片描述
3、将数据集传给神经网络

import os 
import numpy as np
from keras.preprocessing.image import ImageDataGenerator
# 数据集分类后的目录
base_dir = 'D:\\daoandcat\\cats_and_dogs_small'
train_dir = os.path.join(base_dir, 'train')
validation_dir = os.path.join(base_dir, 'validation')
test_dir = os.path.join(base_dir, 'test')
datagen = ImageDataGenerator(rescale = 1. / 255)
batch_size = 20
def extract_features(directory, sample_count):
    features = np.zeros(shape = (sample_count, 4, 4, 512))
    labels = np.zeros(shape = (sample_count))
    generator = datagen.flow_from_directory(directory, target_size = (150, 150), 
                                            batch_size = batch_size,
                                            class_mode = 'binary')
    i = 0
    for inputs_batch, labels_batch in generator:
        #把图片输入VGG16卷积层,让它把图片信息抽取出来
        features_batch = conv_base.predict(inputs_batch)
        #feature_batch 是 4*4*512结构
        features[i * batch_size : (i + 1)*batch_size] = features_batch
        labels[i * batch_size : (i+1)*batch_size] = labels_batch
        i += 1
        if i * batch_size >= sample_count :
            #for in 在generator上的循环是无止境的,因此我们必须主动break
            break
        return features , labels
#extract_features 返回数据格式为(samples, 4, 4, 512)
train_features, train_labels = extract_features(train_dir, 2000)
validation_features, validation_labels = extract_features(validation_dir, 1000)
test_features, test_labels = extract_features(test_dir, 1000)	

4、将抽取的特征输入到我们自己的神经层中进行分类训练

from keras import models
from keras import layers
from keras import optimizers
#构造我们自己的网络层对输出数据进行分类
model = models.Sequential()
model.add(layers.Dense(256, activation='relu', input_dim = 4 * 4 * 512))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(1, activation = 'sigmoid'))
model.compile(optimizer=optimizers.RMSprop(lr = 2e-5), loss = 'binary_crossentropy', metrics = ['acc'])
history = model.fit(train_features, train_labels, epochs = 30, batch_size = 20, 
                    validation_data = (validation_features, validation_labels))

训练过程如图:
在这里插入图片描述
5、训练结果

import matplotlib.pyplot as plt
acc = history.history['acc']
val_acc = history.history['val_acc']
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(1, len(acc) + 1)
plt.plot(epochs, acc, 'bo', label = 'Train_acc')
plt.plot(epochs, val_acc, 'b', label = 'Validation acc')
plt.title('Trainning and validation accuracy')
plt.legend()
plt.figure()
plt.plot(epochs, loss, 'bo', label = 'Training loss')
plt.plot(epochs, val_loss, 'b', label = 'Validation loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()

在这里插入图片描述
在这里插入图片描述

五、总结

1、解释什么是overfit(过拟合)
简单理解就是训练样本得到的输出和期望输出过于一致,而测试样本输出与期望输出相差却很大。为了得到一致假设而使假设变得过度复杂称为过拟合。想像某种学习算法产生了一个过拟合的分类器,这个分类器能够百分之百的正确分类样本数据(即再拿样本中的文档来给它,它绝对不会分错),但也就为了能够对样本完全正确的分类,使得它的构造如此精细复杂,规则如此严格,以至于任何与样本数据稍有不同的文档它全都认为不属于这个类别!
2、什么是数据增强?
数据集增强主要是为了减少网络的过拟合现象,通过对训练图片进行变换可以得到泛化能力更强的网络,更好的适应应用场景。数据增强也叫数据扩增,意思是在不实质性的增加数据的情况下,让有限的数据产生等价于更多数据的价值。
3、如果单独只做数据增强,精确率提高了多少?
大约提高了0.07。
4、然后再添加的dropout层,是什么实际效果?
只进行图像增强获得的模型和进行图像增强与添加dropout层获得的模型,可以发现前者在训练过程中波动会更大,后者在准确上小于前者。两者虽然在准确率有所变小,但是都避免了过拟合。

六、参考资料

https://blog.csdn.net/ssj925319/article/details/117787737
https://blog.csdn.net/qq_43279579/article/details/117298169

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

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

相关文章

Selenium--做任何你想做的事情

大家好,今天为大家介绍Selenium自动化浏览器。就是这样!你可以通过这种力量做任何你想做的事情。 “getDevTools() 方法返回新的 Chrome DevTools 对象,允许您使用 send() 方法发送针对 CDP 的内置 Selenium 命令。这些命令是包装方法&#x…

【C语言】实用调试技巧(vs2019)

简单不先于复杂,而是在复杂之后。 目录 1. 什么是bug? 2. 调试是什么? 2.1 调试定义 2.2 调试的基本步骤 2.3 Debug 和 Release 的介绍 3. Windows 环境调试介绍 3.1 调试环境的准备 3.2 学会快捷键 3.3 调试的时候查看程序当前信息…

找不到msvcp140.dll无法继续执行代码,请重新安装软件MSVCP140.dll,怎么解决?

计算机在运行软件程序或者游戏的时候,提示“找不到msvcp140.dll无法继续执行代码,请重新安装软件”,无法正常启动运行。这个是因为电脑系统中的msvcp140.dll文件丢失或者损坏了,msvcp140.dll是一种动态链接库文件,它是由Microsoft…

显卡资源使用

1.首先,使用校园网访问http://202.206.212.218:8000/,(测试用的ip),部署后为http://59.67.235.242:8000/,出现如下登录界面。 2.目前有9个用户,用户名和密码设置如下: UsernamePass…

最强优化指令大全 | 【Linux技术专题】「系统性能调优实战」终极关注应用系统性能调优及原理剖析(下册)

Linux命令相关查看指标 CPU 指标 vmstat指令 vmstat -n m该命令用于每隔n秒采集系统的性能统计信息,共采集m次。 [rootsvr01]$ vmstat 1 3procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----r b swpd free buff cache …

基于JSP+Servlet的文件上传与下载

基于JSPServlet的文件上传与下载 一、系统介绍二、功能展示1.项目骨架2.单文件上传3.多文件上传4.下载文件1.其他系统实现五.获取源码 一、系统介绍 项目类型:Java web项目 项目名称:基于JSPServlet的文件上传与下载案例 项目架构:B/S架构…

基于单片机智能洗衣机设计与实现

功能介绍 以51单片机作为主控系统;利用STC89C52单片机进行数据处理; 通过2路继电器分别控制洗衣机进水、出水相关逻辑运算;采用L298去掉直流电机实现滚筒正反转;通过单片机进行处理数据,把采集到的数据通过LCD液晶显示…

由于找不到msvcr110.dll,无法继续执行的三个可行修复方案

MSVCR110.dll是一种动态链接库文件,它是由Microsoft Visual Studio 2012的C运行时库的一部分。该文件主要负责提供C代码在Windows操作系统上运行所需的运行时支持。是Windows操作系统中非常重要的文件,如果文件出现损坏或者丢失,计算机系统就…

springboot+echarts+mysql制作数据可视化大屏(滑动大屏)

作者水平低,如有错误,恳请指正!谢谢!!!!! 项目简单,适合大学生参考 分类专栏还有其它的可视化博客哦! 专栏地址:https://blog.csdn.net/qq_559…

【C】初步认识

目录 【1】什么是C语言 【2】第一个C程序解读 【3】数据类型 【4】变量常量 【4.1】定义变量的方法 【4.2】变量的分类 【4.3】变量的使用 【4.4】变量的作用域和生命周期 【4.5】常量分类 【5】字符串 【6】转义字符 【7】注释 【8】选择语句 【9】循环语句 【…

牛客网Java面试题及答案整理( 2023最新版)

大家从 Boss 直聘上或者其他招聘网站上都可以看到 Java 岗位众多,Java 岗位的招聘薪酬天差地别,人才要求也是五花八门。而很多 Java 工程师求职过程中,也是冷暖自知。很多时候技术有,但是面试的时候就是过不了! 为了帮…

SpringSecurity对CSRF的支持实践

【1】什么是CSRF 跨站请求伪造(英语:Cross-site request forgery),也被称为 one-click attack 或者 session riding,通常缩写为 CSRF 或者 XSRF, 是一种挟制用户在当前已登录的Web应用程序上执行非本意的操…

chatgpt赋能python:如何用Python计算居民用电量

如何用Python计算居民用电量 介绍 居民用电量是一个重要的经济指标。对于一个家庭来说,如果能够掌握自己的用电量情况,不仅可以控制开支,还可以提高用电效率,节约能源。而对于电力公司来说,了解居民用电量的变化规律…

vue 实现色板功能

效果&#xff1a; 动态添加颜色 随机色 代码&#xff1a; <divclass"mt-10 firstTitle"v-show"pictureType ! card && pictureType ! table && pictureType ! inventory"><i:class"[colorSystemShow ? el-icon-com-xia…

关于antd的form表单组件的一个天坑。。。

事情是这样的&#xff0c;项目中遇到了一个问题&#xff0c;用表单包裹着着一个Switch组件&#xff0c;提交表单的时候可以将Switch的值一起提交。 form.setFieldsValue({power:0})<Form.Item label"Switch" name"power"><Switch checked{flag}…

autodl算力租用平台应用于pycharm

一、GPU租用选择 1、创建实例 首先进入算力市场 博客以2080为例&#xff0c;选择计费方式&#xff0c;选择合适的主机&#xff0c;选择要创建实例中的GPU数量&#xff0c;选择镜像&#xff08;内置了不同的深度学习框架&#xff09;&#xff0c;最后创建即可 2、SSH远程连…

第五章 linux编译器——gcc/g++的使用

第五章 linux编译器——gcc/g的使用 一、编辑器与编译器的区别二、gcc/g的编译过程前言1、阶段1&#xff1a;预处理&#xff08;头文件、宏的替换&#xff09;&#xff08;1&#xff09;作用&#xff08;2&#xff09;指令&#xff08;3&#xff09;示例 2、阶段2&#xff1a;编…

Linux--用户身份切换: su

①普通用户切换成超级用户且更改路径&#xff1a;su - ②普通用户切换成超级用户且不更改路径&#xff1a;su root 或者 su ③(由普通用户切换来的)超级用户切换回普通用户&#xff1a;Ctrld ④超级用户切换成普通用户&#xff1a;su 普通用户名 ⑤普通用户a切换成普通用户b…

Jetson Nano Swap交换空间增加

依次输入以下命令&#xff0c;可以使交换空间增加3G&#xff0c;解决一些耗尽内存的程序出错。 sudo fallocate -l 3G /var/swapfile sudo chmod 600 /var/swapfile sudo mkswap /var/swapfile sudo swapon /var/swapfile sudo bash -c echo "/var/swapfile swap swap de…

金九银十1060+ 道 Java面试题及答案整理(2023最新版)

前言 今年的金三银四可是被裁员疫情搞得人心慌慌&#xff0c;由于大厂纷纷裁员&#xff0c;面试的竞争难度又上一层&#xff0c;不知道你是否在金三银四中拿到 offer&#xff1f;不过这些都过去了&#xff0c;现在马上迎来的是金九银十&#xff0c;按照往年来说&#xff0c;秋…