Skip to content

Instantly share code, notes, and snippets.

@kmader
Created October 20, 2016 15:22
Show Gist options
  • Save kmader/a55edb442f6c078826a471c75afad8f5 to your computer and use it in GitHub Desktop.
Save kmader/a55edb442f6c078826a471c75afad8f5 to your computer and use it in GitHub Desktop.
UNET to KNIME

Goal: Keras to KNIME

Model Conversion

JSON -> KNIME Workflow

The model file is below as a json output.

Weight Importing

Original (better)

Original weights are stored in HDF5

Keras-JS (alternative)

  • Reads the weights from a single binary file and a metadata file.

Needed Operations

Conv2D

2D convolution operation taking an X, Y, Ca image and making a X, Y, Cb sized image by applying Cb convolutions with a window size Xw, Yw, Ca. For UNET specifically this is (3, 3, 64) in the first layer. For UNET the X, Y dimensions are also reduced to the valid area.

MaxPool2D

2D max pooling operation that takes a X, Y, C image and makes a X//n, Y//n, C sized image where only the maximum value is kept (for UNET, n = 2)

UpSample2D

2D upsampling takes a X, Y, C image and makes a Xn, Yn, C image with the nearest (or zeros) interpolated.

Merge

Merge layers take a X, Y, Ca image and combine them along the channel dimension with another image X, Y, Cb to make a X, Y, Ca+Cb image

References

{
"class_name": "Model",
"keras_version": "1.1.0",
"config": {
"layers": [
{
"class_name": "InputLayer",
"name": "input_3",
"inbound_nodes": [],
"config": {
"input_dtype": "float32",
"name": "input_3",
"sparse": false,
"batch_input_shape": [
null,
1,
64,
80
]
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_58",
"inbound_nodes": [
[
[
"input_3",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 32,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_58",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_59",
"inbound_nodes": [
[
[
"convolution2d_58",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 32,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_59",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "MaxPooling2D",
"name": "maxpooling2d_15",
"inbound_nodes": [
[
[
"convolution2d_59",
0,
0
]
]
],
"config": {
"name": "maxpooling2d_15",
"border_mode": "valid",
"trainable": true,
"pool_size": [
2,
2
],
"strides": [
2,
2
],
"dim_ordering": "th"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_60",
"inbound_nodes": [
[
[
"maxpooling2d_15",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 64,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_60",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_61",
"inbound_nodes": [
[
[
"convolution2d_60",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 64,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_61",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "MaxPooling2D",
"name": "maxpooling2d_16",
"inbound_nodes": [
[
[
"convolution2d_61",
0,
0
]
]
],
"config": {
"name": "maxpooling2d_16",
"border_mode": "valid",
"trainable": true,
"pool_size": [
2,
2
],
"strides": [
2,
2
],
"dim_ordering": "th"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_62",
"inbound_nodes": [
[
[
"maxpooling2d_16",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 128,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_62",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_63",
"inbound_nodes": [
[
[
"convolution2d_62",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 128,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_63",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "MaxPooling2D",
"name": "maxpooling2d_17",
"inbound_nodes": [
[
[
"convolution2d_63",
0,
0
]
]
],
"config": {
"name": "maxpooling2d_17",
"border_mode": "valid",
"trainable": true,
"pool_size": [
2,
2
],
"strides": [
2,
2
],
"dim_ordering": "th"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_64",
"inbound_nodes": [
[
[
"maxpooling2d_17",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 256,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_64",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_65",
"inbound_nodes": [
[
[
"convolution2d_64",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 256,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_65",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "MaxPooling2D",
"name": "maxpooling2d_18",
"inbound_nodes": [
[
[
"convolution2d_65",
0,
0
]
]
],
"config": {
"name": "maxpooling2d_18",
"border_mode": "valid",
"trainable": true,
"pool_size": [
2,
2
],
"strides": [
2,
2
],
"dim_ordering": "th"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_66",
"inbound_nodes": [
[
[
"maxpooling2d_18",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 512,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_66",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_67",
"inbound_nodes": [
[
[
"convolution2d_66",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 512,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_67",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "UpSampling2D",
"name": "upsampling2d_15",
"inbound_nodes": [
[
[
"convolution2d_67",
0,
0
]
]
],
"config": {
"name": "upsampling2d_15",
"size": [
2,
2
],
"trainable": true
}
},
{
"class_name": "Merge",
"name": "merge_9",
"inbound_nodes": [
[
[
"upsampling2d_15",
0,
0
],
[
"convolution2d_65",
0,
0
]
]
],
"config": {
"output_shape": null,
"name": "merge_9",
"dot_axes": -1,
"concat_axis": 1,
"output_shape_type": "raw",
"mode_type": "raw",
"mode": "concat"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_68",
"inbound_nodes": [
[
[
"merge_9",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 256,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_68",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_69",
"inbound_nodes": [
[
[
"convolution2d_68",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 256,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_69",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "UpSampling2D",
"name": "upsampling2d_16",
"inbound_nodes": [
[
[
"convolution2d_69",
0,
0
]
]
],
"config": {
"name": "upsampling2d_16",
"size": [
2,
2
],
"trainable": true
}
},
{
"class_name": "Merge",
"name": "merge_10",
"inbound_nodes": [
[
[
"upsampling2d_16",
0,
0
],
[
"convolution2d_63",
0,
0
]
]
],
"config": {
"output_shape": null,
"name": "merge_10",
"dot_axes": -1,
"concat_axis": 1,
"output_shape_type": "raw",
"mode_type": "raw",
"mode": "concat"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_70",
"inbound_nodes": [
[
[
"merge_10",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 128,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_70",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_71",
"inbound_nodes": [
[
[
"convolution2d_70",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 128,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_71",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "UpSampling2D",
"name": "upsampling2d_17",
"inbound_nodes": [
[
[
"convolution2d_71",
0,
0
]
]
],
"config": {
"name": "upsampling2d_17",
"size": [
2,
2
],
"trainable": true
}
},
{
"class_name": "Merge",
"name": "merge_11",
"inbound_nodes": [
[
[
"upsampling2d_17",
0,
0
],
[
"convolution2d_61",
0,
0
]
]
],
"config": {
"output_shape": null,
"name": "merge_11",
"dot_axes": -1,
"concat_axis": 1,
"output_shape_type": "raw",
"mode_type": "raw",
"mode": "concat"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_72",
"inbound_nodes": [
[
[
"merge_11",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 64,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_72",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_73",
"inbound_nodes": [
[
[
"convolution2d_72",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 64,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_73",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "UpSampling2D",
"name": "upsampling2d_18",
"inbound_nodes": [
[
[
"convolution2d_73",
0,
0
]
]
],
"config": {
"name": "upsampling2d_18",
"size": [
2,
2
],
"trainable": true
}
},
{
"class_name": "Merge",
"name": "merge_12",
"inbound_nodes": [
[
[
"upsampling2d_18",
0,
0
],
[
"convolution2d_59",
0,
0
]
]
],
"config": {
"output_shape": null,
"name": "merge_12",
"dot_axes": -1,
"concat_axis": 1,
"output_shape_type": "raw",
"mode_type": "raw",
"mode": "concat"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_74",
"inbound_nodes": [
[
[
"merge_12",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 32,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_74",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_75",
"inbound_nodes": [
[
[
"convolution2d_74",
0,
0
]
]
],
"config": {
"nb_col": 3,
"activity_regularizer": null,
"nb_filter": 32,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "relu",
"nb_row": 3,
"name": "convolution2d_75",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "same",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
},
{
"class_name": "Convolution2D",
"name": "convolution2d_76",
"inbound_nodes": [
[
[
"convolution2d_75",
0,
0
]
]
],
"config": {
"nb_col": 1,
"activity_regularizer": null,
"nb_filter": 1,
"W_regularizer": null,
"subsample": [
1,
1
],
"W_constraint": null,
"activation": "sigmoid",
"nb_row": 1,
"name": "convolution2d_76",
"b_regularizer": null,
"trainable": true,
"bias": true,
"border_mode": "valid",
"b_constraint": null,
"dim_ordering": "th",
"init": "glorot_uniform"
}
}
],
"name": "model_3",
"output_layers": [
[
"convolution2d_76",
0,
0
]
],
"input_layers": [
[
"input_3",
0,
0
]
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment