我有标题中提到的错误,代码如下
import tensorflow as tf
import numpy as np
import pandas as pd
import seaborn as sns
from random import shuffle
import datetime
from matplotlib import pyplot
from numpy import mean
from numpy import std
from matplotlib import pyplot
from sklearn.model_selection import KFold
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import MaxPooling2D
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Flatten
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.models import load_model
first_branch= Input(shape=(28,28,1))
first_branch_st1 = Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28,1))(first_branch)
first_branch_st2 = MaxPooling2D((2, 2))(first_branch_st1)
first_branch_st3 = Flatten()(first_branch_st2)
first_branch_st4 = Dense(100, activation='relu')(first_branch_st3)
发送以下错误
ValueError Traceback (most recent call last)
/tmp/ipykernel_1973/3453405928.py in <module>
2 first_branch_st1 = Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28,1))(first_branch)
3 first_branch_st2 = MaxPooling2D((2, 2))(first_branch_st1)
----> 4 first_branch_st3 = Flatten()(first_branch_st2)
5 first_branch_st4 = Dense(100, activation='relu')(first_branch_st3)
6
ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.
根据同样错误的问题,当你混淆keras和tf.keras时,会发生同样的错误。但我认为我们已经对进口商品进行了相应的定义,所以除非进口商品之间存在冲突,或者对进口商品的定义不好,否则我认为这不是问题。还有其他已知的解决方案吗?
只有一个错误,Input
没有定义,但仍然与提到的错误无关。使用如下:
first_branch= tf.keras.Input(shape=(28,28,1))
我的建议是请检查tf
的最新版本,例如2.4.1
。
当我更新到google collab(2.6.0)上最新版本的TF时,出现了相同的错误。以前我使用的是2.5,它运行时没有错误。从
更改后from tf.python.keras.applications.efficientnet import EfficientNetB3
from tf.keras.applications.efficientnet import EfficientNetB3
它被解决了。