我的问题是:
假设我在研究癌细胞,让我们简化一下,比如说我在观察一个肿瘤。每个肿瘤都有其平均超大型细胞率,平均异常细胞率,我使用的数据每月一次,在12个月内,我认为每个肿瘤都有一组元组:
[(0.2,0.3),(0.3,0.3)..until I have 12]下面是这个问题的一些示例代码:
dataset = []
for i in range(1000):
train = []
for j in range(0,12):
train.append((np.random.rand(),np.random.rand()))
dataset.append(train)
model = keras.Sequential([
layers.Conv1D(filters=4, kernel_size=2, activation='relu',input_shape=tf.shape(dataset[0])),
layers.Dense(64, activation='relu'),
layers.Dense(1)])
model.predict(dataset)当我尝试执行model.predict()时,我得到:
Negative dimension size caused by subtracting 2 from 1 for '{{node conv1d/conv1d}} = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], explicit_paddings=[], padding="VALID", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true](conv1d/conv1d/ExpandDims, conv1d/conv1d/ExpandDims_1)' with input shapes: [?,1,1,2], [1,2,2,4].你知道我在这里做错了什么吗?我试着查看tf和keras文档,可以构建基本感知器,但也许我不应该使用元组数组,而应该使用其他东西。有什么想法吗?
发布于 2020-07-15 08:19:30
keras/tensorflow不处理元组数据格式。keras接受的最简单的数据格式是numpy数组。按照您的代码片段,这只是为了强制
dataset = []
for i in range(1000):
train = []
for j in range(0,12):
train.append([np.random.rand(), np.random.rand(), np.random.rand()]) # don't use tuple
dataset.append(train)
dataset = np.asarray(dataset) # convert to numpy array
print(dataset.shape)
model = Sequential([
layers.Conv1D(filters=4, kernel_size=2, activation='relu',
input_shape=dataset.shape[1:]),
layers.Dense(64, activation='relu'),
layers.Dense(1)])
model.predict(dataset).shapehttps://stackoverflow.com/questions/62910268
复制相似问题