【发布时间】:2019-12-02 11:59:09
【问题描述】:
假设我有noisy_features 和clean_features。顾名思义,noisy_features 是从嘈杂的输入样本中提取的,而 clean_features 是从干净的输入样本中提取的。 mix_rate 是任意数字,定义将使用多少嘈杂和干净的特征。我想用以下伪代码更改我用 keras 编写的网络:
train_network():
clean_features = get_features(clean_inputs)
noisy_features = get_features(noisy_inputs)
number_of_mix_features = mixture_rate*number_of_features
for epoch in number_of_epochs:
random_indices = random(number_of_mix_features)
input_features = clean_features
input_features[random_indices]=noisy_features[random_indices]
train_network()
函数train_network() 对应于keras 中的model.fit(),但不适用于此上下文,因为model.fit() 内部已经存在epoch 循环。
所以,问题是我无法在 keras 中的每个时期都更改输入特征。如果我在使用之前更改 input_featuresmodel.fit() random_indices 在整个训练期间将保持不变。
我尝试使用回调:
class Noisify(Callback):
def __init__(self,mixture_rate = 0.2):
self.mixture_rate = mixture_rate
def on_epoch_begin(self,epoch,logs={}):
# get input_tensor
'''
mix randomly noisy and clean features here
'''
# set input_tensor
但在这里我不知道获取和设置输入张量的方法,例如 model.get_layer 或 get_weights
有什么建议吗?
【问题讨论】:
标签: python tensorflow keras deep-learning