小编Mos*_*ner的帖子

分配Keras张量的索引条目

我是Keras初学者的一员,所以我提前为任何普遍不好的理解道歉.

我想根据存储在另一个张量中的索引手动设置我的Keras张量的一些值.我相信我理解如何使用tf.gather_nd(我在下面未经测试的尝试)访问张量的条目,我想我明白我只能设置变量的值而不是张量.

为清楚起见,这发生在GAN的生成和识别阶段之间.

gen_out = generator(inputs)

indices_to_reset = Input(shape=(1,),dtype='int32')
new_values = Input(shape=(1,), dtype='int32')

batch_size = K.shape(x)[0]

idx_0 = K.reshape(K.arange(batch_size),(1,))
indices_to_reset = K.reshape(indices_to_reset, (1,))

idx = K.stack((idx_0, indices_to_reset), axis=0)

grabbed_entries = Lambda(lambda x: tf.gather_nd(gen_out,x))(idx)

# Doesn't work
# gen_out[:,indices_to_reset] = new_values

updated_gen_out = ???
Run Code Online (Sandbox Code Playgroud)

python keras

7
推荐指数
1
解决办法
156
查看次数

标签 统计

keras ×1

python ×1