python - 如何在 Numpy 对象中处理 Numpy 对象?
问题描述
我想从这个数据集制作一个多分类模型。
当我处理标签时Keras.preprocessing.image.ImageDataGenerator - flow_from_dataframe
,
y_train:
array([array([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object),
array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=object)],
dtype=object)
它返回上述结果。从这个结果中,我的模型只识别一个 BIG 数组,而不是分隔数组。如何获得正常的 2D 形状 Numpy 数组?
我的代码:
from keras.preprocessing.image import ImageDataGenerator
gen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True)
xray_data['target_vector']
0 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
1 [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0]
2 [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0]
3 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
4 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
...
112115 [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0]
112116 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
112117 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
112118 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
112119 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Name: target_vector, Length: 112120, dtype: object
train_gen = gen.flow_from_dataframe(xray_data, x_col='full_path', y_col='target_vector', class_mode='raw')
X_train, y_train = train_gen.next()
- >以上结果..
感谢您的友好回答!
解决方案
推荐阅读
- opencv - opencv(getTrackbarPos)颜色在图像中没有变化,只有值在变化
- gradle - 无法从以下候选者中找到单个主类 [io.ruin.api.utils.RSAKeyGen, io.ruin.api.utils.PacketSizeTool
- flutter - 如何在我的数字列表中获取下一个索引值?
- javascript - 如何在 React 中连续运行命令
- c# - 从 ac# _context 获取匹配值并更新匹配字段
- kubernetes - 有没有办法备份/恢复/升级 Minikube 集群的无状态部分?
- redis - Redis 更新排序集中的所有分数
- node.js - 无法在 MAC 中卸载/更新 Angular Cli
- android - Jetpack 在灯光模式下撰写动画错误
- javascript - 如何在不支持值时声明带有后备的 CSS 值