Skip to main content

Keras Merge

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

Github PyPI License Python Versions Linux Maintenance Maintenance

Release Notes

VersionComment
v1.1 Copying over weights from source models to merged model (active by default, disable using: km.merge(..., copy_weights=False))
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

Metadata

Release files for keras-merge 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for keras-merge 1.1
File Interpreter ABI Platform
keras_merge-1.1-py3-none-any.whl Python 3 none any Details

Release files / keras_merge-1.1-py3-none-any.whl

Download URL keras_merge-1.1-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e0cecc46c1f5873ef18ab52337e5a71ca51f631504dd8449b1e886489ce8108
BLAKE2b-256 checksum
How to use checksums
b02aa0b3bed68ecb03a60823871ec84d274d83275d7914723a0a5e6fe8a062cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Security for keras-merge 1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page