SHARE
TWEET

Untitled

a guest Jun 20th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. model <- keras_model_sequential() %>%
  2.  
  3.   layer_conv_2d(filters = 32, kernel_size = c(3, 3), activation = "relu", input_shape = c(150, 150, 3)) %>%
  4.   layer_max_pooling_2d(pool_size = c(2, 2)) %>%
  5.  
  6.   layer_conv_2d(filters = 64, kernel_size = c(3, 3), activation = "relu") %>%
  7.   layer_max_pooling_2d(pool_size = c(2, 2)) %>%
  8.  
  9.   layer_conv_2d(filters = 128, kernel_size = c(3, 3), activation = "relu") %>%
  10.   layer_max_pooling_2d(pool_size = c(2, 2)) %>%
  11.  
  12.   layer_conv_2d(filters = 128, kernel_size = c(3, 3), activation = "relu") %>%
  13.   layer_max_pooling_2d(pool_size = c(2, 2)) %>%
  14.  
  15.   layer_flatten() %>%
  16.  
  17.   layer_dropout(rate = 0.5) %>%
  18.  
  19.   layer_dense(units = 512, activation = "relu") %>%
  20.   layer_dense(units = 1, activation = "sigmoid")
  21.  
  22. model %>% compile(
  23.   loss = "binary_crossentropy",
  24.   optimizer = optimizer_rmsprop(lr = 1e-4), metrics = c("acc")
  25. )
  26.  
  27. # Use augmented images:
  28.  
  29. datagen <- image_data_generator(
  30.   rescale = 1/255,
  31.   rotation_range = 40,
  32.   width_shift_range = 0.2,
  33.   height_shift_range = 0.2,
  34.   shear_range = 0.2,
  35.   zoom_range = 0.2,
  36.   horizontal_flip = TRUE
  37. )
  38.  
  39. # Note that the validation data shouldn’t be augmented!
  40.  
  41. test_datagen <-
  42.   image_data_generator(rescale = 1/255)
  43.  
  44. train_generator <- flow_images_from_directory(
  45.   train_dir,
  46.   datagen,
  47.   target_size = c(150, 150),
  48.   batch_size = 32,
  49.   class_mode = "binary"
  50. )
  51.  
  52. validation_generator <- flow_images_from_directory(
  53.   validation_dir,
  54.   test_datagen,
  55.   target_size = c(150, 150),
  56.   batch_size = 32,
  57.   class_mode = "binary"
  58. )
  59.  
  60. ## Train model:
  61.  
  62. history <- model %>% fit_generator(
  63.   train_generator,
  64.   steps_per_epoch = 50,
  65.   epochs = 30,
  66.   validation_data = validation_generator,
  67.   validation_steps = 25
  68. )
  69.      
  70. Error in py_call_impl(callable, dotsargs, dotsargs,dotskeywords) : IndexError: list index out of range
  71.  
  72. stop(structure(list(message = "IndexError: list index out of range", call = py_call_impl(callable, dotsargs, dotsargs,dotskeywords), cppstack = structure(list(file = "", line = -1L, stack = c("/home/boris/R/x86_64-pc-linux-gnu-library/3.6/reticulate/libs/reticulate.so(Rcpp::exception::exception(char const*, bool)+0x7a) [0x7f08f395ea4a]", "/home/boris/R/x86_64-pc-linux-gnu-library/3.6/reticulate/libs/reticulate.so(Rcpp::stop(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x27) [0x7f08f395eba7]", …
  73. finalize at training_utils.py#108
  74. model_iteration at training_generator.py#208
  75. fit_generator at training.py#1426
  76. (structure(function (…) { dots <- py_resolve_dots(list(…)) result <- py_call_impl(callable, dotsargs, dotsargs,dotskeywords) …
  77. do.call(func, args)
  78. call_generator_function(object$fit_generator, list(generator = generator, steps_per_epoch = as.integer(steps_per_epoch), epochs = as.integer(epochs), verbose = as.integer(verbose), callbacks = normalize_callbacks(view_metrics, callbacks), validation_data = validation_data, validation_steps = as_nullable_integer(validation_steps), …
  79. fit_generator(., train_generator, steps_per_epoch = 50, epochs = 30, validation_data = validation_generator, validation_steps = 25)
  80. function_list[k]
  81. withVisible(function_list[k])
  82. freduce(value, ‘_function_list’)
  83. ‘_fseq’(‘_lhs’)
  84. eval(quote(‘_fseq’(‘_lhs’)), env, env)
  85. eval(quote(‘_fseq’(‘_lhs’)), env, env)
  86. withVisible(eval(quote(‘_fseq’(‘_lhs’)), env, env))
  87. model %>% fit_generator(train_generator, steps_per_epoch = 50, epochs = 30, validation_data = validation_generator, validation_steps = 25)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top