Question: 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

```

So, I reshape my train\_data:

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

```

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?

Answer: 
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.
* First Flatten the image
* Apply SMOTE on this flattened image data and its labels
* Reshape the flattened image to RGB image

```py
from imblearn.over_sampling import SMOTE

sm = SMOTE(random_state=42)

train_rows=len(X_train)
X_train = X_train.reshape(train_rows,-1)
(80,30000)

X_train, y_train = sm.fit_resample(X_train, y_train)
X_train = X_train.reshape(-1,100,100,3)
(>80,100,100,3)

```