【垃圾分类3】垃圾分类项目常见错误和解决方法
http://t.csdnimg.cn/f5PWthttp://t.csdnimg.cn/f5PWt
目录
一、搭建环境
1. 创建一个名为CNN(卷积神经网络)的虚拟环境,python版本为3.7.
(base) C:\Users\Administrator>conda create -n CNN python=3.7
选择y,回车。
2. 切换到CNN虚拟环境,安装ipykernel,将虚拟环境写入jupyter lab的kernel中
(base) C:\Users\Administrator>conda activate CNN
(CNN) C:\Users\Administrator>pip install ipykernel
(CNN) C:\Users\Administrator>python -m ipykernel install --user --name CNN --display-name "CNN"
3. 删除 D:\jupyterFile 的所有文件夹
错误一:没有D/jupyterFile
解决方法:在D盘新建文档 D/jupyterFile。
按照教程http://t.csdnimg.cn/67nAP,将 D/jupyterFile 添加到 默认环境修改
4.打开jupyter lab,出现网页代表虚拟环境配置成功。
关闭窗口
错误2:jupyter-lab not found
解决方法:
运行命令 pip install jupyterlab
5. 安装模型所需要的各种库
新开一个Anaconda Prompt窗口,切换到CNN虚拟环境中
(CNN) C:\Users\Administrator>pip install -i https://pypi.doubanio.com/simple/ tf-estimator-nightly==2.8.0.dev2021122109
注:版本号不可以随意更改,python版本要与tensorflow版本相对应。
(CNN) C:\Users\Administrator>pip install tensorflow==2.8.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/
大约需要5分钟
安装成功。
卸载protobuf高版本,下载3.20版本,protobuf高版本会导致tensorflow导入后报错。
(CNN) C:\Users\kg1>pip uninstall protobuf
(CNN) C:\Users\kg1>pip install protobuf==3.20
(CNN) C:\Users\Administrator>pip install SciPy -i https://pypi.tuna.tsinghua.edu.cn/simple
(CNN) C:\Users\Administrator>pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
2.打开jupyter Lab编辑器,不要关闭窗口,关闭窗口后,jupyter lab网页编辑器无法运行
jupyterLab中新建CNN.ipynb文件
二、搭建模型
将 桌面的数据集文件夹 dataset-resized 放在 D:\jupyterFile 路径下。
1 导入模型需要的各种库
切换到到CNN内核环境下进行运行
2 读取数据集,并随机抽取6张图片进行展示
3 数据分组和数据增强
4 CNN模型搭建
5 模型训练
模型训练时间较少,需要等待训练结束
等待训练结束