如何从生成器中获取字典输出,该生成器输出带有用于自定义 keras 图像生成器的字典的数组
Posted
技术标签:
【中文标题】如何从生成器中获取字典输出,该生成器输出带有用于自定义 keras 图像生成器的字典的数组【英文标题】:How to get the dictionary output from a generator, which outputs an array with a dictionary for custom keras image generator 【发布时间】:2020-09-12 00:52:05 【问题描述】:我有一个定制的生成器来输出多个值进行预测。我试图让值对应于给定的图像,但没有成功。这是我的输出:
e(array([[[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
...,
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]]],
[[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
...,
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]]]], dtype=float16),
'HourTime': array([0.3848, 0.2375], dtype=float16),
'MinTime': array([0.633, 0.862], dtype=float16),
'SecTime': array([0.967, 0.717], dtype=float16))
我的输出来自我的生成器:
input_Size = 128
x,y,xrange,yrange = [136,150,47,47]
def ImGenA(directory, files_Loc, Hour, Min, Sec, batch_size):
while True:
batch_paths = imgId = np.random.choice(a = files_Loc.index, size=batch_size)
batch_input = []
batch_Hr = []
batch_Min = []
batch_Sec = []
for i in batch_paths:
img1 = cv2.imread(os.path.join(directory,files_Loc[i]))
img1 = ndimage.rotate(img1, 210)
img1 = cv2.resize (img1, (input_Size,input_Size))
batch_input+=[img1/255]
batch_Hr += [Hour[i]]
batch_Min += [Min[i]]
batch_Sec += [Sec[i]]
batch_x = np.array(batch_input, dtype='float16')
batch_y1 = np.array(batch_Hr, dtype='float16')
batch_y2 = np.array(batch_Min, dtype='float16')
batch_y3 = np.array(batch_Sec, dtype='float16')
yield( batch_x, 'HourTime' : batch_y1, 'MinTime': batch_y2, 'SecTime': batch_y3)
genA = ImGenA(directory=folder, files_Loc= train['ImageLoc'], Hour = train['HrPer'], Min = train['MinPer'], Sec = train['SecPer'],batch_size=2)
b=next(genA)
b[0][0] #provides image at position 0, but how do I find the Y output 'HourTime' at the same position?
我在从生成器运行的保存输出中提取“HourTime”时遇到了困难。抱歉,我假设以前有人问过这个问题,但我不确定我怎么找不到答案。
【问题讨论】:
【参考方案1】:这很简单,一旦你开始工作。
b[1]['HourTime'][0]
为位置 0 提供字典中的“HourTime”。 IE。 0.3848
【讨论】:
以上是关于如何从生成器中获取字典输出,该生成器输出带有用于自定义 keras 图像生成器的字典的数组的主要内容,如果未能解决你的问题,请参考以下文章