使用SMOTE对图像数据进行过采样 [英] Use SMOTE to oversample image data

查看:203
本文介绍了使用SMOTE对图像数据进行过采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CNN进行二进制分类,并且当阳性医学图像:阴性医学图像= 0.4:0.6时,数据不平衡.因此,我想在训练之前使用SMOTE对正医学图像数据进行过采样.但是,数据的尺寸为4D(761,64,64,3),这会导致错误

I'm doing a binary classification with CNNs and the data is imbalanced where the positive medical image : negative medical image = 0.4 : 0.6. So I want to use SMOTE to oversample the positive medical image data before training. However, the dimension of the data is 4D (761,64,64,3) which cause the error

Found array with dim 4. Estimator expected <= 2

所以,我重塑了我的train_data:

So, I reshape my train_data:

X_res, y_res = smote.fit_sample(X_train.reshape(X_train.shape[0], -1), y_train.ravel())

它工作正常.在将其提供给CNN之前,我通过以下方式对其进行了重塑:

And it works fine. Before feed it to CNNs, I reshape it back by:

X_res = X_res.reshape(X_res.shape[0], 64, 64, 3)

现在,我不确定这是否是过采样的正确方法,整形算子会改变图像的构造器吗?

Now, I'm not sure is it a correct way to oversample and will the reshape operator change the images' structer?

推荐答案

我遇到了类似的问题.我曾经使用过重塑功能来重塑图像(基本上将图像展平)

I had a similar issue. I had used the reshape function to reshape the image (basically flattened the image)

X_train.shape
(8000, 250, 250, 3)

ReX_train = X_train.reshape(8000, 250 * 250 * 3)
ReX_train.shape
(8000, 187500)

smt = SMOTE()
Xs_train, ys_train = smt.fit_sample(ReX_train, y_train)

尽管这种方法可悲地缓慢,但有助于提高性能.

Although, this approach is pathetically slow, but helped to improve the performance.

这篇关于使用SMOTE对图像数据进行过采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆