def test_merge_method_seq_concat(self): bx1 = BLayer.Input(shape=(10, )) bx1_1 = BLayer.Input(shape=(10, )) bx2 = BLayer.Input(shape=(10, )) by1 = BLayer.Dense(12, activation="sigmoid")(bx1) bbranch1_node = BModel(bx1, by1)(bx1_1) bbranch2 = BSequential() bbranch2.add(BLayer.Dense(12, input_dim=10)) bbranch2_node = bbranch2(bx2) bz = BLayer.merge([bbranch1_node, bbranch2_node], mode="concat") bmodel = BModel([bx1_1, bx2], bz) kx1 = KLayer.Input(shape=(10, )) kx2 = KLayer.Input(shape=(10, )) ky1 = KLayer.Dense(12, activation="sigmoid")(kx1) kbranch1_node = KModel(kx1, ky1)(kx1) kbranch2 = KSequential() kbranch2.add(KLayer.Dense(12, input_dim=10)) kbranch2_node = kbranch2(kx2) kz = KLayer.merge([kbranch1_node, kbranch2_node], mode="concat") kmodel = KModel([kx1, kx2], kz) input_data = [np.random.random([2, 10]), np.random.random([2, 10])] self.compare_newapi(kmodel, bmodel, input_data, self.convert_two_dense_model)
def test_merge_method_model_concat(self): zx1 = ZLayer.Input(shape=(4, )) zx2 = ZLayer.Input(shape=(5, )) zy1 = ZLayer.Dense(6, activation="sigmoid")(zx1) zbranch1 = ZModel(zx1, zy1)(zx1) zbranch2 = ZLayer.Dense(8)(zx2) zz = ZLayer.merge([zbranch1, zbranch2], mode="concat") zmodel = ZModel([zx1, zx2], zz) kx1 = KLayer.Input(shape=(4, )) kx2 = KLayer.Input(shape=(5, )) ky1 = KLayer.Dense(6, activation="sigmoid")(kx1) kbranch1 = KModel(kx1, ky1)(kx1) kbranch2 = KLayer.Dense(8)(kx2) kz = KLayer.merge([kbranch1, kbranch2], mode="concat") kmodel = KModel([kx1, kx2], kz) input_data = [np.random.random([2, 4]), np.random.random([2, 5])] self.compare_layer(kmodel, zmodel, input_data, self.convert_two_dense)
def test_merge_method_model_concat(self): bx1 = BLayer.Input(shape=(4, )) bx2 = BLayer.Input(shape=(5, )) by1 = BLayer.Dense(6, activation="sigmoid")(bx1) bbranch1 = BModel(bx1, by1)(bx1) bbranch2 = BLayer.Dense(8)(bx2) bz = BLayer.merge([bbranch1, bbranch2], mode="concat") bmodel = BModel([bx1, bx2], bz) kx1 = KLayer.Input(shape=(4, )) kx2 = KLayer.Input(shape=(5, )) ky1 = KLayer.Dense(6, activation="sigmoid")(kx1) kbranch1 = KModel(kx1, ky1)(kx1) kbranch2 = KLayer.Dense(8)(kx2) kz = KLayer.merge([kbranch1, kbranch2], mode="concat") kmodel = KModel([kx1, kx2], kz) input_data = [np.random.random([2, 4]), np.random.random([2, 5])] self.compare_newapi(kmodel, bmodel, input_data, self.convert_two_dense_model)
def test_merge_method_seq_concat(self): zx1 = ZLayer.Input(shape=(10, )) zx2 = ZLayer.Input(shape=(10, )) zy1 = ZLayer.Dense(12, activation="sigmoid")(zx1) zbranch1_node = ZModel(zx1, zy1)(zx1) zbranch2 = ZSequential() zbranch2.add(ZLayer.Dense(12, input_dim=10)) zbranch2_node = zbranch2(zx2) zz = ZLayer.merge([zbranch1_node, zbranch2_node], mode="concat") zmodel = ZModel([zx1, zx2], zz) kx1 = KLayer.Input(shape=(10, )) kx2 = KLayer.Input(shape=(10, )) ky1 = KLayer.Dense(12, activation="sigmoid")(kx1) kbranch1_node = KModel(kx1, ky1)(kx1) kbranch2 = KSequential() kbranch2.add(KLayer.Dense(12, input_dim=10)) kbranch2_node = kbranch2(kx2) kz = KLayer.merge([kbranch1_node, kbranch2_node], mode="concat") kmodel = KModel([kx1, kx2], kz) input_data = [np.random.random([2, 10]), np.random.random([2, 10])] self.compare_layer(kmodel, zmodel, input_data, self.convert_two_dense)
def test_merge_method_sum(self): zx1 = ZLayer.Input(shape=(8, )) zx2 = ZLayer.Input(shape=(6, )) zy1 = ZLayer.Dense(10)(zx1) zy2 = ZLayer.Dense(10)(zx2) zz = ZLayer.merge([zy1, zy2], mode="sum") zmodel = ZModel([zx1, zx2], zz, name="graph1") kx1 = KLayer.Input(shape=(8, )) kx2 = KLayer.Input(shape=(6, )) ky1 = KLayer.Dense(10)(kx1) ky2 = KLayer.Dense(10)(kx2) kz = kmerge([ky1, ky2], mode="sum") kmodel = KModel([kx1, kx2], kz) input_data = [np.random.random([2, 8]), np.random.random([2, 6])] self.compare_layer(kmodel, zmodel, input_data, self.convert_two_dense)
def test_merge_method_sum(self): bx1 = BLayer.Input(shape=(8, )) bx2 = BLayer.Input(shape=(6, )) by1 = BLayer.Dense(10)(bx1) by2 = BLayer.Dense(10)(bx2) bz = BLayer.merge([by1, by2], mode="sum") bmodel = BModel([bx1, bx2], bz, name="graph1") kx1 = KLayer.Input(shape=(8, )) kx2 = KLayer.Input(shape=(6, )) ky1 = KLayer.Dense(10)(kx1) ky2 = KLayer.Dense(10)(kx2) kz = kmerge([ky1, ky2], mode="sum") kmodel = KModel([kx1, kx2], kz) input_data = [np.random.random([2, 8]), np.random.random([2, 6])] self.compare_newapi(kmodel, bmodel, input_data, self.convert_two_dense_model)