tensorflow切分,超参数搜索
来源:3-3 实战tf.strings与ragged tensor
雪落的瞬间
2019-08-03
input = keras.layers.Input(shape=self._x_train.shape[1:])
deep_start_index = self._x_train.shape[1] - deep_shape
input_wide = input[:, :wide_shape]
input_deep = input[:, deep_start_index:]
wide和deep的切分可以放到tensorflow中吗?
因为在进行超参数搜索的时候不能多输入会报错
1回答
-
雪落的瞬间
提问者
2019-08-04
class WideAndDeepDataLayer(keras.layers.Layer):
def __init__(self, train_shape, wide_shape, deep_shape, **kwargs):
self.train_shape = train_shape
self.wide_shape = wide_shape
self.deep_shape = deep_shape
self.deep_start_index = self.train_shape - self.deep_shape
super(WideAndDeepDataLayer, self).__init__(**kwargs)
def build(self, input_shape):
"""构建所需要的参数"""
super(WideAndDeepDataLayer, self).build(input_shape)
def call(self, x):
"""完整正向计算"""
input_wide = tf.reshape(x[:, :self.wide_shape], [-1, self.wide_shape])
input_deep = tf.reshape(x[:, self.deep_start_index:], [-1, self.deep_shape])
return input_wide, input_deep00
相似问题
回答 1
回答 1