我想使用crop_central具有 0.50-1.00 之间的随机浮点数的函数来进行数据增强。然而,在使用numpy.random.uniform(0.50, 1.00)和绘制图像时,裁剪是恒定的。我通过使用 4 个图像并绘制 8 行进行了调试,图像是相同的。
一般来说,问题可以表述如下:如何在数据集映射函数中使用随机数?
def data_augment(image, label=None, seed=2020):
# I want a random number here for every individual image
image = tf.image.central_crop(image, np.random.uniform(0.50, 1.00)) # random crop central
image = tf.image.resize(image, INPUT_SHAPE) # the original image size
return image
train_dataset = (
tf.data.Dataset
.from_tensor_slices((train_paths, train_labels))
.map(decode_image, num_parallel_calls=AUTO)
.map(data_augment, num_parallel_calls=AUTO)
.repeat()
.batch(4)
.prefetch(AUTO)
)
# Code to view the images
for idx, (imgs, _) in enumerate(train_dataset):
show_imgs(imgs, 'image', imgs_per_row=4)
if idx is …Run Code Online (Sandbox Code Playgroud) 对于通过使用model_main.py的Tensorflow API目标检测,当我使用即random_horizontal_flip在data_augmentation_options在train_config我的pipeline.config的,是我的边框也受到了影响?这非常重要,否则这些选项将不适用。这是同一个问题,但没有正确回答。
可以在tensorflow对象检测api配置文件中增强图像,例如:
data_augmentation_options {
random_horizontal_flip {
}
}
data_augmentation_options {
ssd_random_crop {
}
}
Run Code Online (Sandbox Code Playgroud)
如何可视化训练图像来检查增强结果?
感谢您的帮助。
tensorflow tensorboard object-detection-api data-augmentation
我正在尝试绘制由图像生成器创建的图像。到目前为止,这是我提供给生成器的数据代码:
train_img_gen = train_img_data_gen.flow_from_directory(os.path.join(training_dir, 'images'),
target_size=(img_h, img_w),
batch_size=bs,
class_mode=None, # Because we have no class subfolders in this case
shuffle=True,
interpolation='bilinear',
seed=SEED)
#edited part following the already existing answer on stackoverflow
x_batch, y_batch = next(train_img_gen)
for i in range (0,32):
image = x_batch[i]
plt.imshow(image.transpose(2,1,0))
plt.show()
Run Code Online (Sandbox Code Playgroud)
我遵循了这个问题:Keras images,但没有任何成功。
我如何绘制(例如)由我生成的前 n 个图像imageGenerator?
编辑 :
我添加了上述问题中使用的代码,但出现此错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-1a18ce1c1a76> in <module>
54 valid_gen = zip(valid_img_gen, valid_mask_gen)
55
---> 56 x_batch, y_batch = next(train_img_gen)
57 …Run Code Online (Sandbox Code Playgroud) 谁能告诉我上述函数在什么情况下使用以及它们如何影响图像大小?我想调整 Cat V Dogs 图像的大小,但我对如何使用它们有点困惑。
我正在使用 keras 实现 CNN 来执行图像分类,并且我使用 .fit_generator() 方法来训练模型,直到验证停止条件为止我使用了下一个代码:
history_3conv = cnn3.fit_generator(train_data,steps_per_epoch = train_data.n // 98, callbacks = [es,ckpt_3Conv],
validation_data = valid_data, validation_steps = valid_data.n // 98,epochs=50)
Run Code Online (Sandbox Code Playgroud)
停止前的最后两个纪元是下一个:
如图所示,最后的训练准确率为 0.91。然而,当我使用model.evaluate()方法来评估训练、测试和验证集时,我得到了下一个结果:
所以,我的问题是:为什么我有两个不同的值?
我应该使用吗evaluate_generator()?或者我应该修复seed知道flow_from_directory()要执行数据增强我使用了下一个代码:
trdata = ImageDataGenerator(rotation_range=90,horizontal_flip=True)
vldata = ImageDataGenerator()
train_data = trdata.flow(x_train,y_train,batch_size=98)
valid_data = vldata.flow(x_valid,y_valid,batch_size=98)
Run Code Online (Sandbox Code Playgroud)
此外,我知道use_multiprocessing=Falsefit_generator 中的设置会让我显着减慢训练速度。那么你认为最好的解决方案是什么
我已经在以 coco 格式标记和导出的自定义数据上训练了 detectorron2 模型,但现在我想应用增强并使用增强数据进行训练。如果我不使用自定义 DataLoader,而是使用 register_coco_instances 函数,我该如何做到这一点。
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
predictor = DefaultPredictor(cfg)
outputs = predictor(im)
train_annotations_path = "./data/cvat-corn-train-coco-1.0/annotations/instances_default.json"
train_images_path = "./data/cvat-corn-train-coco-1.0/images"
validation_annotations_path = "./data/cvat-corn-validation-coco-1.0/annotations/instances_default.json"
validation_images_path = "./data/cvat-corn-validation-coco-1.0/images"
register_coco_instances(
"train-corn",
{},
train_annotations_path,
train_images_path
)
register_coco_instances(
"validation-corn",
{},
validation_annotations_path,
validation_images_path
)
metadata_train = MetadataCatalog.get("train-corn")
dataset_dicts = DatasetCatalog.get("train-corn")
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.DATASETS.TRAIN = ("train-corn",)
cfg.DATASETS.TEST = ("validation-corn",)
cfg.DATALOADER.NUM_WORKERS = 2
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml") # Let training initialize from model zoo
cfg.SOLVER.IMS_PER_BATCH = 2 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 keras ImageDataGenerator 进行数据增强。我正在从数据框中提取图像,该数据框中包含一列中图像的路径和另一列中的标签。目前,我只是尝试水平翻转图像。但是当我绘制图像时,图像看起来亮度被推到了最大值。我想知道这里发生了什么...有什么想法吗?
datagen = ImageDataGenerator(horizontal_flip=True)
# Configure batch size and retrieve one batch of images
for X_batch, y_batch in datagen.flow_from_dataframe(dataframe=data,
x_col="File name",
y_col="Driving direction",
directory = "Self-Driving-Car/Training Data/",
target_size = (480, 640),
class_mode = "other"):
# Show 9 images
for i in range(0, 9):
plt.subplot(330 + 1 + i)
plt.imshow(X_batch[i])
plt.show()
break
Run Code Online (Sandbox Code Playgroud)


我试图将增强图像保存在文件夹中,但循环正在执行无限次。我的文件夹中有 5000 张图像,但我获得的增强图像数量是无限的。我的目标是获得相同数量的增强图像,即 5000 张。
谢谢
import numpy as np
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(rotation_range=90)
image_path = 'C:/Users/1/Desktop/DEEP/Dataset/Train/1training_c10882.png'
image = np.expand_dims(imageio.imread(image_path), 0)
save_here = 'D:/Augmented DATASET/'
generator = datagen.flow_from_directory('C:/Users/1/Desktop/DEEP/Dataset/Train',target_size=(224,224),
batch_size = 256, class_mode = 'binary')
for inputs,outputs in generator:
pass
Run Code Online (Sandbox Code Playgroud) infinite-loop python-3.x deep-learning keras data-augmentation
我正在创建一个合成数据集来训练需要在图像中查找文档的模型。这些文件远非完美,即它们被折叠、折皱、起皱。
我可以找到几种在 Photoshop 中实现这一点的方法,但我想知道是否有人有更好的想法在 opencv 中进行这种增强,而无需尝试对 Photoshop 过程进行逆向工程。
例如(来自https://www.photoshopessentials.com/photo-effects/folds-creases/):
到:

我正在使用 pytorch 使用github中的代码进行图像分类。我需要在训练我的模型之前添加数据增强,我选择了albumentation来执行此操作。这是我添加专辑时的代码:
data_transform = {
"train": A.Compose([
A.RandomResizedCrop(224,224),
A.HorizontalFlip(p=0.5),
A.RandomGamma(gamma_limit=(80, 120), eps=None, always_apply=False, p=0.5),
A.RandomBrightnessContrast (p=0.5),
A.CLAHE(clip_limit=4.0, tile_grid_size=(8, 8), always_apply=False, p=0.5),
A.ShiftScaleRotate(shift_limit=0.05, scale_limit=0.05, rotate_limit=15, p=0.5),
A.RGBShift(r_shift_limit=15, g_shift_limit=15, b_shift_limit=15, p=0.5),
A.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
ToTensorV2(),]),
"val": A.Compose([
A.Resize(256,256),
A.CenterCrop(224,224),
A.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
ToTensorV2()])}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
KeyError:在 DataLoader 工作进程 0 中捕获 KeyError。
KeyError:“您必须将数据作为命名参数传递给增强,例如:aug(image=image)”
python pytorch data-augmentation albumentations image-classification
python ×7
keras ×4
tensorflow ×4
pytorch ×3
bounding-box ×1
detectron ×1
opencv ×1
python-3.x ×1
tensorboard ×1