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 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_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_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_stack_basic(clean_config): models = [ Conv2D('conv1', 64, 3), Conv2D('conv2', 128, 3), Conv2D('conv3', 256, 3) ] x = tf.ones([32, 64, 64, 3], dtype=tf.float32) st = Stack(models) res = st(x) assert shape(res) == [32, 64, 64, 256]
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_residual_basic(clean_config): m1 = Conv2D('conv1', 3, 3) r = Residual('res1', m1) x = tf.ones([32, 64, 64, 3], dtype=tf.float32) res1 = r(x) res2 = m1(x) assert shape(res1) == [32, 64, 64, 3] with tf.Session() as sess: sess.run(tf.global_variables_initializer()) a, b = sess.run([res1, res2]) assert all_close(a, b) is False
def shape(self): return shape(self.data)
def _(t): return shape(t.unbox())
def _(t, nb_partition, id_partition, axis=0): with tf.variable_scope('split_with_index'): return tf.slice( t, split_start(shape(t), nb_partition, id_partition, axis), split_shape(shape(t), nb_partition, id_partition, axis))
def _(raw_data): return ListModeDataWithoutTOF(const[backends.TensorFlowBackend](raw_data.astype(np.float32), name='lors'), const[backends.TensorFlowBackend](np.ones([shape(raw_data)[0], 1], dtype=np.float32), name='values'))
def test_conv2d_basic(tensorflow_test): m = Conv2D('conv1', 64, 3) x = tf.constant(np.ones([32, 64, 64, 3], np.float32)) y = m(x) assert shape(y) == [32, 64, 64, 64]
def test_upsampling_basic(clean_config): m1 = UpSampling2D('ups1', (2, 2), method=2) x = tf.ones([32, 64, 64, 3], dtype=tf.float32) res = m1(x) assert shape(res) == [32, 128, 128, 3]
def test_downsampling_basic(clean_config): m1 = DownSampling2D('dsp1', (3, 3), (1, 1), 'valid') x = tf.ones([32, 64, 64, 3], dtype=tf.float32) res = m1(x) assert shape(res) == [32, 62, 62, 3]