标签: image-preprocessing

如何解决?AttributeError:模块“keras.preprocessing.image”没有属性“load_img”

    import numpy as np
    from keras.preprocessing import image
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    
    
    %matplotlib inline
    
    
    
    path = './test/paper2.png'
    
    img = image.load_img(path, target_size=(150,150))
    imgplot = plt.imshow(img)
    x = image.img_to_array(img)
    img_test = np.expand_dims(x, axis=0)
    
    classes = model.predict(img_test, batch_size=10)
    
    print(classes)
    paper, rock, scissors = classes[0]
    
    if paper==1.:
        print('paper')
    elif rock==1.:
        print('rock')
    else:
        print('scissors')

Run Code Online (Sandbox Code Playgroud)

输出 :


AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img'
Run Code Online (Sandbox Code Playgroud)

当我尝试跑步时。该错误是什么意思以及如何修复它?帮助大家:)我正在努力学习,我不知道哪一个是错的

python keras tensorflow image-preprocessing jupyter-lab

25
推荐指数
3
解决办法
8万
查看次数

在 Keras 中构建数据时如何使用 repeat() 函数?

我正在对猫和狗的数据集训练二元分类器:
总数据集:10000 张图像
训练数据集:8000 张图像
验证/测试数据集:2000 张图像

Jupyter 笔记本代码:

# Part 2 - Fitting the CNN to the images
train_datagen = ImageDataGenerator(rescale = 1./255,
                                   shear_range = 0.2,
                                   zoom_range = 0.2,
                                   horizontal_flip = True)

test_datagen = ImageDataGenerator(rescale = 1./255)

training_set = train_datagen.flow_from_directory('dataset/training_set',
                                                 target_size = (64, 64),
                                                 batch_size = 32,
                                                 class_mode = 'binary')

test_set = test_datagen.flow_from_directory('dataset/test_set',
                                            target_size = (64, 64),
                                            batch_size = 32,
                                            class_mode = 'binary')

history = model.fit_generator(training_set,
                              steps_per_epoch=8000,
                              epochs=25,
                              validation_data=test_set,
                              validation_steps=2000)
Run Code Online (Sandbox Code Playgroud)

我在 CPU 上训练它没有问题,但是当我在 GPU 上运行时,它抛出了这个错误:

Found 8000 images belonging …
Run Code Online (Sandbox Code Playgroud)

deep-learning keras tensorflow image-preprocessing

10
推荐指数
1
解决办法
1万
查看次数

如何实施ZCA美白?蟒蛇

我试图实施ZCA美白并找到一些文章来做,但它们有点令人困惑..有人可以为我照亮吗?

任何提示或帮助表示赞赏!

这是我读过的文章:

http://courses.media.mit.edu/2010fall/mas622j/whiten.pdf http://bbabenko.tumblr.com/post/86756017649/learning-low-level-vision-feautres-in-10-lines-of

我尝试了几件事,但大多数我都不明白,我被锁定了一步.现在我以此为基础重新开始:

dtype = np.float32
data = np.loadtxt("../inputData/train.csv", dtype=dtype, delimiter=',', skiprows=1)
img = ((data[1,1:]).reshape((28,28)).astype('uint8')*255)
Run Code Online (Sandbox Code Playgroud)

python correlated pca image-preprocessing

9
推荐指数
2
解决办法
2万
查看次数

Numpy:零均值数据和标准化

我在教程中看到(没有进一步的解释)我们可以将数据处理为零均值x -= np.mean(x, axis=0)并使用数据标准化x /= np.std(x, axis=0).任何人都可以在代码上详细说明这两个部分,我从文档中得到的只是np.mean计算算术平均值沿特定轴计算平均值np.std并为标准偏差计算.

python numpy image-preprocessing

9
推荐指数
3
解决办法
2万
查看次数

Keras VGG16预处理输入模式

我正在使用Keras VGG16模型

我已经看到,有一个preprocess_input方法可以与VGG16模型结合使用。该方法似乎在imagenet_utils.py中调用preprocess_input方法,方法(取决于大小写)在imagenet_utils.py中调用_preprocess_numpy_input方法

preprocess_inputmode哪些期待“朱古力”,“TF”,或“火炬”的说法。如果我在带有TensorFlow后端的Keras中使用模型,我应该绝对使用mode="tf"吗?

如果是,这是否是因为Keras加载的VGG16模型受过经过相同预处理(即,将输入图像的范围从[0,255]更改为输入范围[-1,1])的图像进行了训练?

另外,用于测试模式的输入图像也应进行此预处理吗?我相信最后一个问题的答案是肯定的,但我希望得到保证。

我希望Francois Chollet能够正确地做到这一点,但是看他是不是https://github.com/fchollet/deep-learning-models/blob/master/vgg16.py,或者我使用错了mode="tf"

更新信息

@FalconUA将我带到牛津VGG,那里有一个模型部分,其中包含16层模型的链接。通过以下模型 16层模型中的链接可以找到有关将preprocessing_input mode参数tf缩放为-1到1并caffe减去一些平均值的信息信息页面。在“说明”部分中,它说:

“在本文中,模型表示为经过比例抖动训练的配置D。输入图像应通过均值像素(而不是均值图像)相减为零。即,应减去以下BGR值:[103.939, 116.779,123.68]。”

deep-learning keras tensorflow image-preprocessing vgg-net

8
推荐指数
2
解决办法
3622
查看次数

Keras图像增强:如何选择"每个步骤的步骤"参数并在训练期间包括特定的增强?

我正在使用Keras训练图像分类CNN.使用该ImageDataGenerator功能,我将一些随机变换应用于训练图像(例如旋转,剪切,缩放).我的理解是,这些转换在传递给模型之前随机应用于每个图像.

但有些事情我不清楚:

1)如何在训练时确保包含图像的特定旋转(例如90°,180°,270°).

2)steps_per_epoch参数model.fit_generator应设置为数据集的唯一样本数除以flow_from_directory方法中定义的批量大小.当使用上述图像增强方法时,这是否仍然适用,因为它们增加了训练图像的数量?

谢谢,马里奥

python image deep-learning keras image-preprocessing

6
推荐指数
1
解决办法
630
查看次数

使用opencv python从二进制图像中删除小点

我有一个二进制图像,我想使用 opencv python 从图像中删除小白点。您可以在此处参考我的问题,在此处输入链接描述

我的原图是

在此处输入图片说明

我希望输出图像为:

在此处输入图片说明

python opencv image-preprocessing

6
推荐指数
2
解决办法
4859
查看次数

以编程方式将扫描图像划分为单独的图像

为了提高 OCR 质量,我需要对扫描的图像进行预处理。有时我需要用几张图片(页面上的组件并且它们处于不同的角度 - 例如,一次扫描一些纸质文档)对图像进行 OCR,例如:

在此处输入图片说明

是否可以自动以编程方式将此类图像划分为包含每个逻辑文档的单独图像?例如使用 ImageMagick 之类的工具或其他工具?是否有针对此类问题的解决方案/技术?

ocr imagemagick image-processing image-preprocessing

5
推荐指数
1
解决办法
823
查看次数

Keras image_dataset_from_directory 未找到图像

我想从我有大约 5000 张图像的目录中加载数据(类型“png”)。但是它返回一个错误,说当明显有图像时没有图像。这段代码:

width=int(wb-wa)
height=int(hb-ha)
directory = '/content/drive/My Drive/Colab Notebooks/Hair/Images'
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
    directory, labels=densitat, label_mode='int',
    color_mode='rgb', batch_size=32, image_size=(width, height), shuffle=True, seed=1,
    validation_split=0.2, subset='training', follow_links = False)
Run Code Online (Sandbox Code Playgroud)

返回:

ValueError: Expected the lengths of `labels` to match the number of files in the target directory. len(labels) is 5588 while we found 0 files in /content/drive/My Drive/Colab Notebooks/Hair/Images.
Run Code Online (Sandbox Code Playgroud)

我可以看到图像: 带有图像的文件夹结构的 Colab 视图

问题出在哪儿?我需要使用这个函数来批量加载数据,因为我有一个大数据集

keras tensorflow image-preprocessing tensorflow-datasets

5
推荐指数
2
解决办法
2478
查看次数

这是在python中美白图像的正确方法吗?

我正在尝试zero-centerwhiten CIFAR10数据集,但我得到的结果看起来像随机噪音!
Cifar10数据集包含60,000大小的彩色图像32x32.训练集包含50,000和测试集10,000分别包含图像.
以下代码片段显示了我为使数据集变白而执行的过程:

# zero-center
mean = np.mean(data_train, axis = (0,2,3)) 
for i in range(data_train.shape[0]):
    for j in range(data_train.shape[1]):
        data_train[i,j,:,:] -= mean[j]

first_dim = data_train.shape[0] #50,000
second_dim = data_train.shape[1] * data_train.shape[2] * data_train.shape[3] # 3*32*32
shape = (first_dim, second_dim) # (50000, 3072) 

# compute the covariance matrix
cov = np.dot(data_train.reshape(shape).T, data_train.reshape(shape)) / data_train.shape[0] 
# compute the SVD factorization of the data covariance matrix
U,S,V = np.linalg.svd(cov) …
Run Code Online (Sandbox Code Playgroud)

python image-preprocessing image-whitening

4
推荐指数
1
解决办法
6106
查看次数