R error while using SoundClass package and Tensor Flow on Apple Silicon M1 Pro

Viewed 26

I'm working on acoustic analysis using the R package SoundClass. This package depends on Tensorflow and Keras. This is the code I'm running:

require(reticulate)
library(tensorflow)
library(soundClass)
library(keras)

use_condaenv("tensorflow")
library(shiny)
library(shinyFiles)
#keras::install_keras()

# Example of European bat echolocation
setwd("~/Documents/Soundscaping/SoundClass")
train_recs_folder <- "./dataExample/training_recordings/"
label_database <- "./dataExample/db_bat_calls.sqlite3"

train_calls <- spectro_calls(files_path = train_recs_folder, db_path = label_database,
                             spec_size = 20, window_length = 0.5, overlap = 0.5, 
                             dynamic_range = 100, freq_range = c(10,80), tx = "auto")

input_shape <- c(train_calls$parameters$img_rows, train_calls$parameters$img_cols, 1)

num_classes <- train_calls$parameters$num_classes

model_path <- system.file("model_architectures", "model_vgg_sequential.R", package = "soundClass")

source(model_path, local = TRUE)

model %>% keras::compile(optimizer = keras::optimizer_sgd(learning_rate = 0.01, 
                                                          momentum = 0.9, nesterov = TRUE),
                         loss = "categorical_crossentropy", metrics = "accuracy")

model %>% keras::fit( x = train_calls$data_x, y = train_calls$data_y, batch_size = 128, epochs = 10, callbacks = list(keras::callback_early_stopping(patience = 4, monitor = "val_accuracy"), keras::callback_model_checkpoint("./fitted_model.hdf5", monitor = "val_accuracy", save_best_only = TRUE), keras::callback_csv_logger("./fitted_model_log.csv")), shuffle = TRUE, validation_split = 0.3, verbose = 1)

metadata <- train_metadata(train_calls)
save(metadata, file = "./fitted_model_metadata.RDATA")

However, after running the code I got the following error:

Loaded Tensorflow version 2.9.2
Warning message:
`src_sqlite()` was deprecated in dplyr 1.0.0.
Please use `tbl()` directly with a database connection 
Metal device set to: Apple M1 Pro

systemMemory: 16.00 GB
maxCacheSize: 5.33 GB

2022-09-11 15:13:33.367156: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2022-09-11 15:13:33.367396: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)
2022-09-11 15:13:33.923166: W tensorflow/core/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz
Epoch 1/10
2022-09-11 15:13:34.301972: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:113] Plugin optimizer for device_type GPU is enabled.

 *** caught segfault ***
address 0xbc1e0cf7b6c0, cause 'invalid permissions'

Traceback:
 1: py_call_impl(callable, dots$args, dots$keywords)
 2: (function (...) {    dots <- py_resolve_dots(list(...))    result <- py_call_impl(callable, dots$args, dots$keywords)    if (convert)         result <- py_to_r(result)    if (is.null(result))         invisible(result)    else result})(batch_size = 128L, epochs = 10L, verbose = 1L, validation_split = 0.3,     shuffle = TRUE, class_weight = NULL, sample_weight = NULL,     initial_epoch = 0L, x = <environment>, y = <environment>,     callbacks = list(<environment>, <environment>, <environment>,         <environment>))
 3: do.call(object$fit, args)
 4: fit.keras.engine.training.Model(., x = train_calls$data_x, y = train_calls$data_y,     batch_size = 128, epochs = 10, callbacks = list(keras::callback_early_stopping(patience = 4,         monitor = "val_accuracy"), keras::callback_model_checkpoint("./fitted_model.hdf5",         monitor = "val_accuracy", save_best_only = TRUE), keras::callback_csv_logger("./fitted_model_log.csv")),     shuffle = TRUE, validation_split = 0.3, verbose = 1)
 5: keras::fit(., x = train_calls$data_x, y = train_calls$data_y,     batch_size = 128, epochs = 10, callbacks = list(keras::callback_early_stopping(patience = 4,         monitor = "val_accuracy"), keras::callback_model_checkpoint("./fitted_model.hdf5",         monitor = "val_accuracy", save_best_only = TRUE), keras::callback_csv_logger("./fitted_model_log.csv")),     shuffle = TRUE, validation_split = 0.3, verbose = 1)
 6: model %>% keras::fit(x = train_calls$data_x, y = train_calls$data_y,     batch_size = 128, epochs = 10, callbacks = list(keras::callback_early_stopping(patience = 4,         monitor = "val_accuracy"), keras::callback_model_checkpoint("./fitted_model.hdf5",         monitor = "val_accuracy", save_best_only = TRUE), keras::callback_csv_logger("./fitted_model_log.csv")),     shuffle = TRUE, validation_split = 0.3, verbose = 1)
An irrecoverable exception occurred. R is aborting now ...
zsh: segmentation fault  Rscript SC_test_v1.R

The code runs the epoch 1/10 and then stopped. Is it the *** caught segfault *** address 0xbc1e0cf7b6c0, cause 'invalid permissions' the error causing the problem?

Thanks

0 Answers
Related