I have the error mentioned in the title, with the following code
JavaScript
x
29
29
1
import tensorflow as tf
2
import numpy as np
3
import pandas as pd
4
import seaborn as sns
5
from random import shuffle
6
import datetime
7
from matplotlib import pyplot
8
9
from numpy import mean
10
from numpy import std
11
from matplotlib import pyplot
12
from sklearn.model_selection import KFold
13
from tensorflow.keras.datasets import mnist
14
from tensorflow.keras.utils import to_categorical
15
from tensorflow.keras.models import Sequential
16
from tensorflow.keras.layers import Conv2D
17
from tensorflow.keras.layers import MaxPooling2D
18
from tensorflow.keras.layers import Dense
19
from tensorflow.keras.layers import Flatten
20
from tensorflow.keras.optimizers import SGD
21
22
from tensorflow.keras.models import load_model
23
24
first_branch= Input(shape=(28,28,1))
25
first_branch_st1 = Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28,1))(first_branch)
26
first_branch_st2 = MaxPooling2D((2, 2))(first_branch_st1)
27
first_branch_st3 = Flatten()(first_branch_st2)
28
first_branch_st4 = Dense(100, activation='relu')(first_branch_st3)
29
This sends the following error
JavaScript
1
10
10
1
ValueError Traceback (most recent call last)
2
/tmp/ipykernel_1973/3453405928.py in <module>
3
2 first_branch_st1 = Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28,1))(first_branch)
4
3 first_branch_st2 = MaxPooling2D((2, 2))(first_branch_st1)
5
----> 4 first_branch_st3 = Flatten()(first_branch_st2)
6
5 first_branch_st4 = Dense(100, activation='relu')(first_branch_st3)
7
6
8
9
ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.
10
According to the question asked with the same error it happens when you mix up keras and tf.keras. But i think have defined the imports accordingly, so unless there is a clash between imports or a bad definition of them i do not think that’s the problem. There is another known solution?
Advertisement
Answer
There’s only 1 bug, Input
is not defined but still unrelated to the error mentioned. Use below:
JavaScript
1
2
1
first_branch= tf.keras.Input(shape=(28,28,1))
2
My advice is to please check on the latest versions of tf
e.g. 2.4.1
.