Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Layer input_spec must be an instance of InputSpec. #51

Open
minwg1021 opened this issue Jun 17, 2024 · 2 comments
Open

TypeError: Layer input_spec must be an instance of InputSpec. #51

minwg1021 opened this issue Jun 17, 2024 · 2 comments

Comments

@minwg1021
Copy link

import numpy as np
import cvnn.layers as complex_layers
import tensorflow as tf


def get_dataset():
        (train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.cifar10.load_data()
        train_images = train_images.astype(dtype=np.complex64) / 255.0
        test_images = test_images.astype(dtype=np.complex64) / 255.0
        return (train_images, train_labels), (test_images, test_labels)


(train_images, train_labels), (test_images, test_labels) = get_dataset()        # to be done by each user

print(train_images)

model = tf.keras.models.Sequential()
model.add(complex_layers.ComplexInput(input_shape=(32, 32, 3)))                     # Always use ComplexInput at the start
model.add(complex_layers.ComplexConv2D(32, (3, 3), activation='relu'))
model.add(complex_layers.ComplexAvgPooling2D((2, 2)))
model.add(complex_layers.ComplexConv2D(64, (3, 3), activation='relu'))
model.add(complex_layers.ComplexMaxPooling2D((2, 2)))
model.add(complex_layers.ComplexConv2D(64, (3, 3), activation='relu'))
model.add(complex_layers.ComplexFlatten())
model.add(complex_layers.ComplexDense(64, activation='relu'))
model.add(complex_layers.ComplexDense(10, activation='softmax'))
model.compile(optimizer='adam',
        loss='categorial_crossentropy',
        metrics=['accuracy'])
model.summary()

Hello! I have a question about the Input Spec.
The code above is the example code provided in the Doc. When I run the code, I get the following error:
TypeError: Layer input_spec must be an instance of InputSpec. Got: InputSpec(min_ndim=4)
Is there a way to resolve this issue?

I will be waiting for your response. Thank you!

@NEGU93
Copy link
Owner

NEGU93 commented Jun 20, 2024

Hello, I don't see any input_spec layer in your code. Can you provide the full error message trace?

@minwg1021
Copy link
Author

Traceback (most recent call last):
  File "d:\Research\extra\src\DL\AutoEncoder\[2024-06-04]CVNN_ae\tmp.py", line 19, in <module>
    model.add(complex_layers.ComplexConv2D(32, (3, 3), activation='relu'))
  File "C:\Users\USER\anaconda3\envs\cvnn\lib\site-packages\cvnn\layers.py", line 717, in __init__
    super(ComplexConv2D, self).__init__(
  File "C:\Users\USER\anaconda3\envs\cvnn\lib\site-packages\cvnn\layers.py", line 329, in __init__
    self.input_spec = InputSpec(min_ndim=self.rank + 2)
  File "C:\Users\USER\anaconda3\envs\cvnn\lib\site-packages\keras\engine\base_layer.py", line 3075, in __setattr__
    super(tf.__internal__.tracking.AutoTrackable, self).__setattr__(
  File "C:\Users\USER\anaconda3\envs\cvnn\lib\site-packages\tensorflow\python\trackable\base.py", line 205, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "C:\Users\USER\anaconda3\envs\cvnn\lib\site-packages\keras\engine\base_layer.py", line 1243, in input_spec
    raise TypeError(
TypeError: Layer input_spec must be an instance of InputSpec. Got: InputSpec(min_ndim=4)

Thank you for your response!
The error message shown above is the entire error message trace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants