ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor

Viewed 4667

This error appears when i try load model with my custom layer.

model = load_model('my_model.h5', custom_objects={'MyLayer': MyLayer})

Im trying to visualize what is happening in my custom keras layer. Im working with images of BrainMRI and trying just to flip them in layer.

import tensorflow as tf
from keras import backend as K
from keras.layers import Layer
import matplotlib.pyplot as plt


class MyLayer(Layer):
    def __init__(self, num_outputs, name = 'MyLayer', **kwargs):
        super(MyLayer, self).__init__(**kwargs)
        self.num_outputs = num_outputs


    def build(self, input_shape):
        self.kernel = self.add_weight(name='kernel',
                                  shape=(input_shape[1], self.num_outputs),
                                  initializer='normal', trainable=True)

        super(MyLayer, self).build(input_shape)

    def call(self, inputs, **kwargs):
        flipped = K.reverse(inputs,axes=0)
        return flipped

    def compute_output_shape(self, input_shape):
        return (input_shape[0], self.output_dim)

    def get_config(self):
        base = super(MyLayer, self).get_config()
        base['num_outputs'] = self.num_outputs
        return dict(list(base.items()))

I tried reinstall keras as some thread was recommending but nothing happens

0 Answers
Related