你好,我正在尝试使用我电脑上图像的数据制作张量流的基本示例。 但是我一直都遇到此错误:“ ValueError:无法找到可以处理输入的数据适配器:,(包含类型为“”“的值)”
这是我生成数据的方式:
import numpy as np # for array operations
import matplotlib.pyplot as plt # to show image
import os # to move through directories
import cv2 # to make image operations
import random
import pickle
DATADIR=r"C:\Users\...\mnist_png\training"
DIGITS = ["0","1","2","3","4","5","6","7","8","9"]
training_data = []
for digit in DIGITS:
path = os.path.join(DATADIR, digit)
class_num = DIGITS.index(digit)
for img in os.listdir(path):
img_array = cv2.imread(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
training_data.append([img_array, class_num])
random.shuffle(training_data)
X = []
y = []
for features, label in training_data:
X.append(features)
y.append(label)
X = np.array(X).reshape(-1, 28, 28, 1)
pickle_out = open("X.pickle", "wb")
pickle.dump(X, pickle_out)
pickle_out.close()
pickle_out = open("y.pickle", "wb")
pickle.dump(y, pickle_out)
pickle_out.close()
这是我从中得到错误的张量流模型:
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(10))
model.add(Activation('sigmoid'))
model.compile(
loss="sparse_categorical_crossentropy",
optimizer="adam",
metrics=['accuracy']
)
model.fit(X, y, batch_size=32, validation_split=0.1)
请帮助我
答案 0 :(得分:1)
之后
for features, label in training_data:
X.append(features)
y.append(label)
您必须添加
y = np.array(y)