我是ML的新手,最后一行代码有一个错误:
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense , Dropout, Activation, Flatten, Conv2D, MaxPooling2D
import pickle
x = pickle.load(open("x.pickle","rb"))
y = pickle.load(open("y.pickle","rb"))
x=x/255.0
model = Sequential()
model.add( Conv2D(64, (3,3), input_shape = x.shape[1:]) )
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(64, (3,3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss="categorical_crossentropy",
optimizer="adam",
metrics=['accuracy'])
model.fit(x, y,batch_size=10,validation_split=0.1)
这就是错误
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_10844\1395261416.py in <module>
----> 1 model.fit(x, y,batch_size=10,validation_split=0.1)
~\anaconda3\lib\site-packages\keras\utils\traceback_utils.py in error_handler(*args, **kwargs)
68 # To get the full stack trace, call:
69 # `tf.debugging.disable_traceback_filtering()`
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
~\anaconda3\lib\site-packages\keras\engine\data_adapter.py in train_validation_split(arrays, validation_split)
1662 unsplitable = [type(t) for t in flat_arrays if not _can_split(t)]
1663 if unsplitable:
-> 1664 raise ValueError(
1665 "`validation_split` is only supported for Tensors or NumPy "
1666 "arrays, found following types in the input: {}".format(unsplitable)
ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following types in the input: [<class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>]
我试图编译我的模型,但在最后一行model.fit(x, y,batch_size=10,validation_split=0.1)
中发现了一个错误。
1条答案
按热度按时间xeufq47z1#
如错误中所述,在拟合模型之前,需要将输入和目标数据转换为
numpy
数组或tensor
。可以使用以下代码将
x
和y
数据更改为数组:我使用kaggle的同类data复制了这段代码。
请查找随附的gist以供参考。