神经n的ipynb文件错误

2024-10-06 14:24:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我有点傻,所以在这里容忍我。我一直在youtube上观看Siraj Raval,并尝试使用他在视频https://www.youtube.com/watch?v=cAICT4Al5Ow中创建的神经网络。我有两个单独的图像文件夹,一个是含有疟疾的细胞,另一个是健康细胞。我不知道用什么来验证数据。在包含图像的路径上使用load_data函数之后,我遇到了一个错误,我不知道如何解决这个问题。似乎我使用的软件包中有一个应该具有该功能的软件包工作不正常。你知道吗

我已经将每个单元格的代码(我正在使用jupyter笔记本)压缩到这个文本文件中。文本之间的长空格表示它们在不同的单元格中。我不知道这是否重要。你知道吗

http://textuploader.com/d0nv0


Tags: 数据https图像文件夹com视频youtubewww
2条回答

再次检查minute 2:45 你失踪了

from parser import load_data

但这似乎是一个自定义模块,没有提供。您需要的是将文件夹中的所有文件读取到数组/列表中。下面是一个代码,可以让您开始:

import os
from PIL import Image
import cv2
images = []
images2 = []

folder="somepics"
for filename in os.listdir(folder):
    if not filename.startswith('.'):
        print(filename)

        #read with PIL
        img = Image.open("{0}/{1}".format(folder, filename))
        print(type(img))
        images.append(img)

        #read with cv2
        img2 = cv2.imread(filename)
        print(type(img2))
        images2.append(img)

请记住,图像的大小必须相同。你可能需要重塑它们。你知道吗

你需要一个发电机。参见^{} function section documentation of Keras,或者更好地使用ImageDataGenerator。下一段代码是从Building an image classification model using very little data复制粘贴的:

目录结构

data/
    train/
        dogs/ ### 1024 pictures
            dog001.jpg
            dog002.jpg
            ...
        cats/ ### 1024 pictures
            cat001.jpg
            cat002.jpg
            ...
    validation/
        dogs/ ### 416 pictures
            dog001.jpg
            dog002.jpg
            ...
        cats/ ### 416 pictures
            cat001.jpg
            cat002.jpg

代码

# used to rescale the pixel values from [0, 255] to [0, 1] interval
datagen = ImageDataGenerator(rescale=1./255)

# automagically retrieve images and their classes for train and validation sets
train_generator = datagen.flow_from_directory(
        train_data_dir,
        target_size=(img_width, img_height),
        batch_size=16,
        class_mode='binary')

validation_generator = datagen.flow_from_directory(
        validation_data_dir,
        target_size=(img_width, img_height),
        batch_size=32,
        class_mode='binary')

请参阅Building an image classification model using very little data中的原始代码。你知道吗

相关问题 更多 >