python - 如何使用 Python 的“imblearn”库将 (120, 100, 100) 形状的图像数据重塑为 (120, 10000) 形状以进行欠采样?
问题描述
我正在使用Python的imblearn库进行欠采样。
必要代码:
undersample = RandomUnderSampler(sampling_strategy='majority')
X_under, y_under = undersample.fit_resample(X, y)
这里X是我的(120, 100, 100) 形状的图像数据集 & ,y是(120,) 形状的图像标签。我在这里遇到错误。但是如果我给X的形状 (x_value, y_value)那么它就可以了。有什么方法可以将(120, 100, 100) 形状的图像数据转换为(120, 10000)形状?
解决方案
将图像数据转换为 numpy 数组,然后重塑,这将解决它
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)
推荐阅读
- java - Humble Video 拍摄给定时间的快照
- node.js - 无需重新加载窗口即可自动刷新 Firebase 身份验证?
- python - 如何在没有 html/js 的情况下捕获 fastapi websocket 消息?
- javascript - jQuery 不计算表单上的增值税
- html - 样式化基于 Bootstrap 的组件
- node.js - 构建一个restAPI,没有视图。我还应该采用 MVC 作为良好做法吗?
- chisel - 可以像verilog一样雕刻打印时间
- rust - rust中的“eq()”和“==”有什么区别
- python - bot 不会记录 on_message 事件
- python - Opencv“len(contour)”返回错误值