如何使用 Python 的 "imblearn" 库将 (120, 100, 100) 形状的图像数据重塑为 (120, 10000) 形状以欠采样?

How can I reshape (120, 100, 100) shaped image data to (120, 10000) shape to undersample using "imblearn" library of Python?

我正在使用 imblearnPython 进行欠采样。

所需代码:

undersample = RandomUnderSampler(sampling_strategy='majority')
X_under, y_under = undersample.fit_resample(X, y)

这里 X 是我的图像数据集 & (120, 100, 100) shapey是图像的标签,其形状为(120,)。我在这里遇到错误。 但是,如果我给出 X of shape (x_value, y_value) 那么它就起作用了。 有什么方法可以将图像数据的 (120, 100, 100) 形状 转换为 (120, 10000) 形状?

将图像数据转换成一个numpy数组,然后reshape,这样就解决了

import numpy as np
# assuming X is the image data of shape (120,100,100)
X = np.asarray(image)
X_reshape = X.reshape(120,10000)