无法使用 numpy 数组训练模型



我正在训练以下浮点数的自动编码器。

input_img = Input(shape=(2623,1), name='input')
x = ZeroPadding1D(1)(input_img)
x = Conv1D(32, 3, activation='relu', padding='same', use_bias=False)(input_img)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling1D(2, padding='same')(x)
x = Conv1D(16, 3, activation='relu', padding='same', use_bias=False)(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling1D(2, padding='same')(x)
x = Conv1D(16,3, activation='relu', padding='same', use_bias=False)(x)
x = BatchNormalization(axis=-1)(x)
encoded = MaxPooling1D(2, padding='same')(x)

x = Conv1D(16,3, activation='relu', padding='same', use_bias=False)(encoded)
x = BatchNormalization(axis=-1)(x)
x = UpSampling1D(2)(x)
x = Conv1D(16,3, activation='relu', padding='same', use_bias=False)(x)
x = BatchNormalization(axis=-1)(x)
x = UpSampling1D(2)(x)
x = Conv1D(32, 3, activation='relu', padding='same', use_bias=False)(x)  #input_shape=(30, 1))
x = BatchNormalization(axis=-1)(x)  
x = UpSampling1D(2)(x)
x = Cropping1D(cropping=(0, 1))(x) #Crop nothing from input but crop 1 element from the end
decoded = Conv1D(1, 3, activation='sigmoid', padding='same', use_bias=False)(x)  
autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='rmsprop', loss='binary_crossentropy')

x = Input(shape=(16, 300), name="input")
h = x
h = Conv1D(filters=300, kernel_size=16,
activation="relu", padding='same', name='Conv1')(h)
h = MaxPooling1D(pool_size=16, name='Maxpool1')(h)

我必须将数据转换为 numpy 数组才能处理它,但是当模型开始训练时,我得到:

值错误:无法将字符串转换为浮点数:

发生这种情况是因为我的训练数据如下所示:

训练[0][1] # 一个训练数据数

array(['0.001758873'], dtype=object)

我该怎么做才能避免训练数据中的"dtype=object",或者我是否必须将其转换为其他内容? 谢谢!

也许,作为预处理步骤,您可以使用以下内容将对象类型数组类型转换为浮点数组:

# if float32 is the desired & appropriate datatype
train = train.astype(numpy.float32)

相关内容

  • 没有找到相关文章

最新更新