Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image_load : 'float' object cannot be interpreted as an integer #1481

Closed
danli349 opened this issue Dec 30, 2024 · 2 comments · Fixed by #1486
Closed

image_load : 'float' object cannot be interpreted as an integer #1481

danli349 opened this issue Dec 30, 2024 · 2 comments · Fixed by #1486

Comments

@danli349
Copy link

Hello:

library(keras3)
img <- image_load("book_images/flamingo.jpg", target_size = c(224, 224))

How should I solve this problem? Thanks

'float' object cannot be interpreted as an integerTraceback:

1. do.call(keras$utils$load_img, args)
2. (structure(function (path, color_mode = "rgb", target_size = NULL, 
 .     interpolation = "nearest", keep_aspect_ratio = FALSE) 
 . {
 .     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
 . }, class = c("python.builtin.function", "python.builtin.object"
 . ), py_object = <environment>))(path = "book_images/flamingo.jpg", 
 .     target_size = c(224, 224))
3. py_call_impl(callable, call_args$unnamed, call_args$named)
4. stop(structure(list(message = "TypeError: 'float' object cannot be interpreted as an integer\nRun `reticulate::py_last_error()` for details.", 
 .     call = py_call_impl(callable, call_args$unnamed, call_args$named)), class = c("python.builtin.TypeError", 
 . "python.builtin.Exception", "python.builtin.BaseException", "python.builtin.object", 
 . "error", "condition"), py_object = <environment>))
@t-kalinowski
Copy link
Member

Thanks for the bug report, this will fixed shortly.

You can workaround for now by casting target_size to integer:

image_load(image_path, target_size = as.integer(c(224, 224)))
# or 
image_load(image_path, target_size = shape(224, 224))

@danli349
Copy link
Author

@t-kalinowski It works, Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants