Skip to content

About the get_incoming_shape function in network.py #101

@yaodaoboy

Description

@yaodaoboy

In network.py, the author use the code as followed to judge whether the incoming variable is a np.array, list, or tuple object

def get_incoming_shape(incoming):
   """ Returns the incoming data shape """
   if isinstance(incoming, tf.Tensor):
       return incoming.get_shape().as_list()
   elif type(incoming) in [np.array, list, tuple]:
       return np.shape(incoming)
   else:
       raise Exception("Invalid incoming layer.")

However, np.array is a function to change a array-like object to a np.ndarray object. np.ndarray is the type name instead of np.array.

So, the correct code may be like as followed:

def get_incoming_shape(incoming):
    """ Returns the incoming data shape """
    if isinstance(incoming, tf.Tensor):
        return incoming.get_shape().as_list()
    elif type(incoming) in [np.ndarray, list, tuple]:
    # elif isinstance(incoming, (np.ndarray, list, tuple)):
        return np.shape(incoming)
    else:
        raise Exception("Invalid incoming layer.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions