Dask DataFrame用于拟合Keras模型

时间:2018-11-03 14:00:04

标签: keras dask

我有一个Dask DataFrame,我想用它来拟合Keras自动编码器模型:

DataFrame:

import dask.dataframe as dd
input_df = dd.read_csv(file_path)
input_df.dtypes

_2 float64 _3 float64 _4 float64 _5 float64 ...

Keras模型:

autoencoder = Sequential()
autoencoder.add(Dense(dense[0], input_shape=(dense[0],), activation = 'relu' ))
autoencoder.add(Dense(dense[1], activation = 'relu' ))
autoencoder.add(Dense(dense[2], activation = 'relu' ))
autoencoder.add(Dense(dense[3], activation = 'relu' ))
autoencoder.add(Dense(dense[0], activation = 'relu' ))

autoencoder.compile(loss='mse',
          optimizer='adam',
          metrics=['mse'])

当我通过DataFrame进行拟合时:

autoencoder.fit(input_df, input_df,
                batch_size=batch_size,
                epochs=epochs,
                verbose=1,
                validation_split = val_split)

我得到了错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-23-d0480d8a460d> in <module>()
      3                     epochs=epochs,
      4                     verbose=1,
----> 5                     validation_split = val_split)

~/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
    950             sample_weight=sample_weight,
    951             class_weight=class_weight,
--> 952             batch_size=batch_size)
    953         # Prepare validation data.
    954         do_validation = False

~/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)
    799                 for (ref, sw, cw, mode) in
    800                 zip(y, sample_weights, class_weights,
--> 801                     feed_sample_weight_modes)
    802             ]
    803             # Check that all arrays have the same length.

~/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/training.py in <listcomp>(.0)
    797             sample_weights = [
    798                 standardize_weights(ref, sw, cw, mode)
--> 799                 for (ref, sw, cw, mode) in
    800                 zip(y, sample_weights, class_weights,
    801                     feed_sample_weight_modes)

~/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/training_utils.py in standardize_weights(y, sample_weight, class_weight, sample_weight_mode)
    522     else:
    523         if sample_weight_mode is None:
--> 524             return np.ones((y.shape[0],), dtype=K.floatx())
    525         else:
    526             return np.ones((y.shape[0], y.shape[1]), dtype=K.floatx())

~/anaconda3/envs/py36/lib/python3.6/site-packages/numpy/core/numeric.py in ones(shape, dtype, order)
    201 
    202     """
--> 203     a = empty(shape, dtype, order)
    204     multiarray.copyto(a, 1, casting='unsafe')
    205     return a

TypeError: 'float' object cannot be interpreted as an integer

将感谢您的帮助!谢谢!

0 个答案:

没有答案