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

python call error #51

Closed
senyang1107 opened this issue Mar 10, 2024 · 0 comments · Fixed by #53
Closed

python call error #51

senyang1107 opened this issue Mar 10, 2024 · 0 comments · Fixed by #53
Assignees
Labels
bug Something isn't working

Comments

@senyang1107
Copy link

senyang1107 commented Mar 10, 2024

Hello, I ran the sample code and got an error when I got to the error.

Code:

library(magrittr)
x_data <- matrix(data = runif(500,0,1),nrow = 50,ncol = 10)
y_data <-  ifelse(runif(50,0,1) > 0.6, 1L,0L) %>% as.matrix()

x_data2 <- matrix(data = runif(500,0,1),nrow = 50,ncol = 10)
y_data2 <-  ifelse(runif(50,0,1) > 0.6, 1L,0L) %>% as.matrix()

library(keras)
library(tensorflow)
library(kerastuneR)

build_model = function(hp) {
  
  model = keras_model_sequential()
  model %>% layer_dense(units = hp$Int('units',
                                       min_value = 32,
                                       max_value = 512,
                                       step=  32),input_shape = ncol(x_data),
                        activation =  'relu') %>%
    layer_dense(units = 1, activation = 'softmax') %>%
    compile(
      optimizer = tf$keras$optimizers$Adam(
        hp$Choice('learning_rate',
                  values=c(1e-2, 1e-3, 1e-4))),
      loss = 'binary_crossentropy',
      metrics = 'accuracy')
  return(model)
}

tuner = RandomSearch(
  build_model,
  objective = 'val_accuracy',
  max_trials = 5,
  executions_per_trial = 3,
  directory = 'my_dir',
  project_name = 'helloworld')


tuner %>% search_summary()

tuner %>% fit_tuner(x_data,y_data,
                    epochs = 5, 
                    validation_data = list(x_data2,y_data2))

When running the fit_tuner function, the following error occurs:Traceback (most recent call last):
  File "C:\Users\WANGSE~1\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\keras_tuner\engine\base_tuner.py", line 270, in _try_run_and_update_trial
    self._run_and_update_trial(trial, *fit_args, **fit_kwargs)
  File "C:\Users\WANGSE~1\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\keras_tuner\engine\base_tuner.py", line 235, in _run_and_update_trial
    results = self.run_trial(trial, *fit_args, **fit_kwargs)
  File "C:\Users\WANGSE~1\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\keras_tuner\engine\tuner.py", line 279, in run_trial
    for execution in range(self.executions_per_trial):
TypeError: 'float' object cannot be interpreted as an integer
Error in py_call_impl(callable, call_args$unnamed, call_args$named) : 
  RuntimeError: Number of consecutive failures excceeded the limit of 3.
Traceback (most recent call last):
  File "C:\Users\WANGSE~1\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\keras_tuner\engine\base_tuner.py", line 270, in _try_run_and_update_trial
    self._run_and_update_trial(trial, *fit_args, **fit_kwargs)
  File "C:\Users\WANGSE~1\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\keras_tuner\engine\base_tuner.py", line 235, in _run_and_update_trial
    results = self.run_trial(trial, *fit_args, **fit_kwargs)
  File "C:\Users\WANGSE~1\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\keras_tuner\engine\tuner.py", line 279, in run_trial
    for execution in range(self.executions_per_trial):
TypeError: 'float' object cannot be interpreted as an integer

There seems to be an error in the data type, but I'm not familiar with python and would appreciate your help.

@turgut090 turgut090 self-assigned this Mar 11, 2024
@turgut090 turgut090 added the bug Something isn't working label Mar 11, 2024
@turgut090 turgut090 linked a pull request Apr 13, 2024 that will close this issue
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants