Skip to main content

Allows to merge two keras.Models

Project description

Keras Merge

Keras Merge allows to merge two Keras model instances without having access to their generating functions.

Release Notes

VersionComment
v1.0 Initial Release

Usage

import keras_merge as km

from keras import Model, Input
import numpy as np
from keras.utils import plot_model

def model(mul: bool) -> Model:
    x = Input(shape=(2, 3))
    y = Input(shape=(2, 3))
    if mul: z = x * y
    else:   z = x + y
    return Model(inputs=[x, y], outputs=z)

A = model(True)
B = model(False)
C = km.merge(A, B,				# models
	[*A.inputs, B.inputs[0]],	# inputs
	B.outputs,					# outputs
	[							# mapping [(src->dst), ...]
		(A.outputs[0], B.inputs[1])
	]
)

a = np.random.rand(1, 2, 3)
b = np.random.rand(1, 2, 3)
c = np.random.rand(1, 2, 3)

d = A([a, b])
e = B([c, d])
f = C([a, b, c])

print("A+B:    ", np.reshape(e, -1))
print("Merged: ", np.reshape(f, -1))

plot_model(A, to_file='A.png')
plot_model(B, to_file='B.png')
plot_model(C, to_file='C.png')

How to build

pip3 install illyrian
illyrian keras_merge.json
pip3 install keras_merge-1.0-py3-none-any.whl

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keras_merge-1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file keras_merge-1.0-py3-none-any.whl.

File metadata

  • Download URL: keras_merge-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for keras_merge-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fd7f89e6541d9e78ddb45c01f4bf7d009bc170675372781d11c12694acd14f6
MD5 a209ee72b130b7ce7a401d764691b4fa
BLAKE2b-256 bf1d4434922b6a2c74f1d6a4f545bdbaa4c46e2a92dd1f7327ef631de297ae5e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page