def kernel(self, inputs): x = inputs[self.KEYS.TENSOR.HITS] x = flatten(x) m = identity models = [] for i in range(3): models += [Dense(self.config(self.KEYS.CONFIG.NB_UNITS) [i], info='dense_{}'.format(i)), ReLU, DropOut()] # models.append(DropOut()) models.append( Dense(self.config(self.KEYS.CONFIG.MAX_NB_HITS), info='dense_end')) seq = self.graphs.get('seq', Stack(info='stack', models=models)) return seq(x)
def test_base_model_inheritance_ver1(clean_config): x = tf.ones([32, 64, 64, 3], dtype=tf.float32) m1 = Conv2D('conv', 32, 3) m2 = Dense('dense', 160) m3 = Stack([m1, m2]) res1 = m3(x) assert shape(res1) == [32, 64, 64, 160]
def kernel(self, inputs): x = inputs[self.KEYS.TENSOR.HITS] x = flatten(x) m = identity models = [] for i in range(len(self.config(self.KEYS.CONFIG.NB_UNITS))): models += [Dense(self.config(self.KEYS.CONFIG.NB_UNITS) [i], info='dense_{}'.format(i)), ReLU, DropOut()] models.append( Dense(self.config(self.KEYS.CONFIG.MAX_NB_HITS), info='dense_end')) if self.graphs.get(self.KEYS.GRAPH.SEQUENTIAL) is None: self.graphs[self.KEYS.GRAPH.SEQUENTIAL] = Sequential( info='stack', models=models) return self.graphs[self.KEYS.GRAPH.SEQUENTIAL](x)
def test_base_model_inheritance_ver3(clean_config): x = tf.ones([32, 64, 64, 160], dtype=tf.float32) m1 = Conv2D('conv1', 32, 3) m7 = Conv2D('conv2', 3, 3) m8 = Dense('dense', 128) m6 = Inception('inception', m7, m7, [m1, m8]) res3 = m6(x) assert shape(res3) == [32, 64, 64, 3]
def test_base_model_inheritance_ver2(clean_config): x = tf.ones([32, 64, 64, 3], dtype=tf.float32) m4 = Conv2D('conv', 160, 3) m9 = Dense('dense', 160) x = m9(x) m5 = Residual('res', m4) res2 = m5(x) assert shape(res2) == [32, 64, 64, 160]
def test_Inception_basic(clean_config): x = tf.constant(np.ones([32, 64, 64, 3], np.float32)) m1 = Conv2D('conv3', 64, 3) m2 = Dense('dense1', 128) paths = [Conv2D('conv_{}'.format(i), 32 + 32 * i, 3) for i in range(3)] m = Inception('inception1', m1, m2, paths) y = m(x) assert shape(y) == [32, 64, 64, 128]
def test_merge_basic(clean_config): m1 = Dense('d1', 256) m2 = Conv2D('conv1', 64, 3) m3 = Conv2D('conv2', 128, 3) concate = partial(concat, axis=3) m = Merge(merger=concate, models=[m2, m3]) x = tf.ones([32, 64, 64, 3], dtype=tf.float32) res = m(x) res = m1(res) assert shape(res) == [32, 64, 64, 256]
def test_merge_parameter(clean_config): m1 = Dense('d1', 256) m2 = Conv2D('conv1', 64, 3) m3 = Conv2D('conv2', 128, 3) concate = partial(concat, axis=3) m = Merge(merger=concate, models=[m2, m3]) x = tf.ones([32, 64, 64, 3], dtype=tf.float32) res = m(x) res = m1(res) assert m.parameters[0].get_shape() == (3, 3, 3, 64)
def test_Inception_parameter(clean_config): x = tf.constant(np.ones([32, 64, 64, 3], np.float32)) m1 = Conv2D('conv4', 64, 3) m2 = Dense('dense2', 128) paths = [Conv2D('conv_{}'.format(i), 32 + 32 * i, 3) for i in range(3)] m = Inception('inception2', m1, m2, paths) y = m(x) assert m.parameters[0].get_shape() == (3, 3, 3, 64) assert m.parameters[1].get_shape() == (64, ) assert m.parameters[2].get_shape() == (3, 3, 64, 32) assert m.parameters[3].get_shape() == (32, )