卷积神经网络

  1. 基础知识
    参考:https://zhuanlan.zhihu.com/p/342698821
  2. 数据集下载
    参考:https://blog.csdn.net/ASLLTQ/article/details/127573268
  3. 监测异常图片
'''
此代码是查找出一个文件夹里面,
所有图片读取错误,再删除
'''
import os
import shutil
import warnings
import cv2
import io
from PIL import Image
warnings.filterwarnings("error", category=UserWarning)
base_dir = "./train/cats"#删除图片的根目录
i = 0
def is_read_successfully(file):
try:
imgFile = Image.open(file)#这个就是一个简单的打开成功与否
return True
except Exception:
return False
for parent, dirs, files in os.walk(base_dir):#(root,dirs,files)
for file in files:
if not is_read_successfully(os.path.join(parent, file)):
print(os.path.join(parent, file))
# os.remove(os.path.join(parent, file)) #真正使用时,这一行要放开,自己一般习惯先跑一遍,没有错误了再删除,防止删错。
i = i + 1
print(i)
  1. 图形转换相关
from keras.preprocessing import image
# 读取并调整图像大小
img = image.load_img(img_path,target_size=(150,150))
# 将其转换为形状为(150,150,3)的数组
x = image.img_to_array(img)
# 将其形状改变为(1,150,150,3)
x = x.reshape((1,)+x.shape)
# 显示图像
plt.imshow(image.array_to_img(x))
  1. module 'keras.layers.preprocessing' has no attribute 'sequence'
    参考:https://blog.csdn.net/XUQIAN_LIUQIAN/article/details/129196503
  2. pad_sequence
    参考:https://blog.csdn.net/wcy23580/article/details/84957471

posted on   朝朝暮Mu  阅读(12)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示