当我在RStudio中使用tensorflow_1.9,decrypter_0.2.1.9000,keras_2.1.6.9005运行以下代码时
library(keras)
library(decryptr)
library(tensorflow)
captchas <- list.files("insert path here", full.names = TRUE, pattern = ".*png")%>%
read_captcha(ans_in_path = TRUE, vocab = c(letters, 0:9)) %>%
join_captchas()
set.seed(902192)
i <- sample.int(captchas$n, 10000,replace = TRUE)
train <- list(y = captchas$y[i,,,drop = FALSE], x = captchas$x[i,,,,drop =
FALSE])
test <- list(y = captchas$y[-i,,,drop = FALSE], x = captchas$x[-i,,,,drop =
FALSE])
model <- keras_model_sequential()
model %>%
layer_conv_2d(
input_shape = dim(train$x)[-1],
filters = 16,
kernel_size = c(5, 5),
padding = "same",
activation = "relu") %>%
layer_max_pooling_2d() %>%
layer_conv_2d(
filters = 32,
kernel_size = c(5, 5),
padding = "same",
activation = "relu") %>%
layer_max_pooling_2d() %>%
layer_conv_2d(
filters = 64,
kernel_size = c(5, 5),
padding = "same",
activation = "relu") %>%
layer_max_pooling_2d() %>%
layer_flatten() %>%
layer_dense(units = 256) %>%
layer_dropout(.1) %>%
layer_dense(units = prod(dim(train$y)[-1])) %>%
layer_reshape(target_shape = dim(train$y)[-1]) %>%
layer_activation("softmax")
model %>%
compile(
optimizer = "adam",
loss = "categorical_crossentropy",
metrics = "accuracy")
model %>%
fit(
x = train$x,
y = train$y,
batch_size = 4160,
epochs = 30,
shuffle = TRUE,
validation_data = list(test$x, test$y))
这是输出: py_call_impl中的错误(可调用,dots $ args,dots $ keywords): AttributeError:“ Tensor”对象没有属性“ assign”