2
我想通過R stdio中的keras張量流創建分類模型,但我在下面得到一個錯誤。請問有人有線索嗎?這是我第一次使用keras或深度學習。由於用keras構建R工作室的分類模型
> set.seed(10)
> ind <- sample(2, nrow(stdk), replace=TRUE, prob=c(0.80, 0.2))
> stdk.train <- stdk[ind==1, ]
> stdk.test <- stdk[ind==2, ]
> change.train <- stdk[ind==1, 5]
> change.test <- stdk[ind==2, 5]
> stdk.trainLabels <- to_categorical(change.train)
> stdk.testLabels <- to_categorical(change.test)
>
> modelk <- keras_model_sequential()
> modelk %>%
+ layer_dense(units = 23, activation = 'relu', input_shape = c(40)) %>%
+ layer_dense(units = 9, activation = 'softmax')
> summary(modelk)
Model
Layer (type) Output Shape Param #
================================================================================================================
dense_1 (Dense) (None, 23) 943
________________________________________________________________________________________________________________
dense_2 (Dense) (None, 9) 216
總PARAMS:1159個 可訓練PARAMS:1159 非可訓練PARAMS:0
> get_layer(modelk, index = 1)
Dense
> modelk$layers
[[1]]
Dense
[[2]]
Dense
> modelk$inputs
[[1]]
Tensor("dense_1_input:0", shape=(?, 40), dtype=float32)
> modelk$outputs
[[1]]
Tensor("dense_2/Softmax:0", shape=(?, 9), dtype=float32)
> modelk %>% compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = c('accuracy')
+)
> modelk %>% fit(
+ stdk.train,
+ stdk.trainLabels,
+ epochs = 200,
+ batch_size = 5 )
Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: No data provided for "dense_1_input". Need data for each key in: ['dense_1_input']
Detailed traceback:
File "C:\Users\A\ANACON~1\envs\R-TENS~1\lib\site-packages\tensorflow\contrib\keras\python\keras\models.py", line 844, in fit
initial_epoch=initial_epoch)
File "C:\Users\A\ANACON~1\envs\R-TENS~1\lib\site-packages\tensorflow\contrib\keras\python\keras\engine\training.py", line 1406, in fit
batch_size=batch_size)
File "C:\Users\A\ANACON~1\envs\R-TENS~1\lib\site-packages\tensorflow\contrib\keras\python\keras\engine\training.py", line 1300, in _standardize_user_data
exception_prefix='model input')
File "C:\Users\A\ANACON~1\envs\R-TENS~1\lib\site-packages\tensorflow\contrib\keras\python\keras\engine\training.py", line 82, in _standardize_input_data
'". Need data for each key in: ' + str(names))
謝謝!這是我的問題。 – ronomal