【发布时间】:2018-11-03 12:43:16
【问题描述】:
我正在使用 Python+Tensorflow 在高性能计算集群上进行 CNN 训练。我正在训练卷积神经网络,但数据集相对较小。所以我正在实施技术来增强它。现在这是我第一次研究核心计算机视觉问题,所以对它比较陌生。
随着训练图像数量的增加,需要 cv2 的 imgaug 包 (https://github.com/aleju/imgaug) 似乎是完美的,并且是增加图像数量的简单解决方案。我使用python 2.7安装了opencv2,所有需要的python包都在本地运行(这里没有使用env/Anaconda/Docker)。
实际上,我正在尝试从 here 运行这段代码:
import os
import imgaug as ia
from imgaug import augmenters as iaa
import scipy
import cv2
import numpy as np
# optional check my hint import scipy.misc import imwrite
# optional check my hint import scipy.misc import imsave
ia.seed(1)
# Example batch of images.
# The array has shape (32, 64, 64, 3) and dtype uint8.
images = np.array(
[ia.quokka(size=(64, 64)) for _ in range(32)],
dtype=np.uint8
)
seq = iaa.Sequential([
iaa.Fliplr(0.5), # horizontal flips
iaa.Crop(percent=(0, 0.1)), # random crops
# Small gaussian blur with random sigma between 0 and 0.5.
# But we only blur about 50% of all images.
iaa.Sometimes(0.5,
iaa.GaussianBlur(sigma=(0, 0.5))
),
# Strengthen or weaken the contrast in each image.
iaa.ContrastNormalization((0.75, 1.5)),
# Add gaussian noise.
# For 50% of all images, we sample the noise once per pixel.
# For the other 50% of all images, we sample the noise per pixel AND
# channel. This can change the color (not only brightness) of the
# pixels.
iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05*255), per_channel=0.5),
# Make some images brighter and some darker.
# In 20% of all cases, we sample the multiplier once per channel,
# which can end up changing the color of the images.
iaa.Multiply((0.8, 1.2), per_channel=0.2),
# Apply affine transformations to each image.
# Scale/zoom them, translate/move them, rotate them and shear them.
iaa.Affine(
scale={"x": (0.8, 1.2), "y": (0.8, 1.2)},
translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)},
rotate=(-25, 25),
shear=(-8, 8)
)
], random_order=True) # apply augmenters in random order
images_aug = seq.augment_images(images)
使用此代码创建 .py 文件后,我已将此文件复制到包含 50 张图像 (.jpg) 的文件夹中。 代码本身运行完美(没有遇到错误),但似乎.jpg没有加载到.py文件中,即使我设置了文件夹路径,它也不会加载图像。此外,没有写入新文件。
问题 1:我想我必须将图像作为数组加载到 .py 或 cv2 中,但我找不到任何如何加载和编写它们的示例,因为我从未做过这样的事情。有什么帮助吗?
问题 2:在这种情况下使用的最佳界面是什么?所有图像都存储在文件夹或 .xlsx 文件中。
(提示:不幸的是,这可能是一个基于 Keras 的选项(Link)?或者我找到了这两个选项,但我无法使用它们 scipy.ndimage.imread 和 scipy.misc.imsave)
【问题讨论】:
标签: python image opencv tensorflow scipy