-
Notifications
You must be signed in to change notification settings - Fork 282
Open
Description
Hi,
I was running the code for training the MNIST dataset and got an error. Below is my code and the error:
library(keras3)
# Load the MNIST dataset
mnist <- dataset_mnist()
train_images <- mnist$train$x
train_labels <- mnist$train$y
test_images <- mnist$test$x
test_labels <- mnist$test$y
# Inspect the data
str(train_images)
str(train_labels)
str(test_images)
str(test_labels)
# Build the model
model <- keras_model_sequential() %>%
layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>%
layer_dropout(rate = 0.4) %>%
layer_dense(units = 128, activation = 'relu') %>%
layer_dropout(rate = 0.3) %>%
layer_dense(units = 10, activation = 'softmax')
# Compile the model
compile(model,
optimizer = "rmsprop",
loss = "sparse_categorical_crossentropy",
metrics = "accuracy")
# Reshape and normalize the data
train_images <- array(train_images, dim = c(60000, 28 * 28))
train_images <- train_images / 255
test_images <- array(test_images, dim = c(10000, 28 * 28))
test_images <- test_images / 255
# Train the model
fit(model, train_images, train_labels, epochs = 5, batch_size = 128)
I got:
Error in py_call_impl(callable, call_args$unnamed, call_args$named) :
OverflowError: Python int too large to convert to C long
Run `reticulate::py_last_error()` for details.
reticulate::py_last_error()
── Python Exception Message ────────────────────────────────────────────────────────────────────────────────
Traceback (most recent call last):
File "C:\Users\DucDo\ONEDRI~1\DOCUME~1\VIRTUA~1\R-TENS~1\Lib\site-packages\keras\src\utils\traceback_utils.py", line 122, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\DucDo\ONEDRI~1\DOCUME~1\VIRTUA~1\R-TENS~1\Lib\site-packages\keras\src\backend\tensorflow\numpy.py", line 2079, in signbit
tf.constant(0x80000000, dtype=tf.int32),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OverflowError: Python int too large to convert to C long
── R Traceback ─────────────────────────────────────────────────────────────────────────────────────────────
▆
1. ├─generics::fit(...)
2. └─keras3:::fit.keras.src.models.model.Model(...)
3. ├─base::do.call(object$fit, args)
4. └─reticulate (local) `<python.builtin.method>`(...)
5. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)
See `reticulate::py_last_error()$r_trace$full_call` for more details.
reticulate::py_last_error()$r_trace$full_call
[[1]]
fit(model, train_images, train_labels, epochs = 5, batch_size = 128)
[[2]]
fit.keras.src.models.model.Model(model, train_images, train_labels,
epochs = 5, batch_size = 128)
[[3]]
do.call(object$fit, args)
[[4]]
(function (x = NULL, y = NULL, batch_size = NULL, epochs = 1L,
verbose = "auto", callbacks = NULL, validation_split = 0,
validation_data = NULL, shuffle = TRUE, class_weight = NULL,
sample_weight = NULL, initial_epoch = 0L, steps_per_epoch = NULL,
validation_steps = NULL, validation_batch_size = NULL, validation_freq = 1L)
{
cl <- sys.call()
cl[[1L]] <- list2
call_args <- split_named_unnamed(eval(cl, parent.frame()))
result <- py_call_impl(callable, call_args$unnamed, call_args$named)
if (py_get_convert(callable))
result <- py_to_r(result)
if (is.null(result))
invisible(result)
else result
})(x = <environment>, y = <environment>, batch_size = 128L, epochs = 5L,
verbose = "auto", callbacks = list(<environment>))
[[5]]
py_call_impl(callable, call_args$unnamed, call_args$named)
How to fix this problem? Thanks.
Metadata
Metadata
Assignees
Labels
No labels