I'm trying to get into deep learning with R. Using various blogs online I'm trying to test their code and see how they actually work. With keras, I'm not sure why but everytime I run a modelfunction It keeps crashing.
I'm sorry if I haven't provided enough information. I'm running an AMD GPU and CPU
Example code section
history <- model %>% fit_generator(
train_generator,
steps_per_epoch = 100,
epochs = 100,
validation_data = validation_generator,
validation_steps = 50,
)
use_multiprocessing=False
an also
hist <- model %>% fit_generator(
# training data
train_image_array_gen,
# epochs
steps_per_epoch = as.integer(train_samples / batch_size),
epochs = epochs,
# validation data
validation_data = valid_image_array_gen,
validation_steps = as.integer(valid_samples / batch_size),
# print progress
verbose = 2,
callbacks = list(
# save best model after every epoch
callback_model_checkpoint("C:/Users/My Account/Desktop/fruits_checkpoints.h5", save_best_only = TRUE),
)
It looks like the problem is with Keras using tensorflow-gpu. Try running the model after installing tensorflow cpu version. Since, you are using AMD gpu, you may not be able to use the tensorflow gpu version with cudnn libraries.
Related
I get an error when i try to run this code. i followed a guide on youtube for building a neural network. Everything works except when i try to run this code to fit the model.
history <- modnn %>% fit(
train_X_matrix, train_Y, epochs = 50, batch_size = 600,
validation_data = list(validation_X_matrix,validation_Y))
```
the error i get when i try to run the code above, all the names you see are the names of the columns. So the features of the model:
[error in visual studio](https://i.stack.imgur.com/ZaPXw.png)
some extra info about the variables i use. Here i created a matrix of the input variables. They did this in the guide. I tried train_x_data as input then it gave the same error but immediately so not after 1 epoch
```
# dependent and independent variables in 1 dataframe
train_X_data <- data.frame(train_X,train_y)
validation_X_data <- data.frame(validation_X,validation_y)
train_X_matrix <- model.matrix(average_daily_rate ~. -1 , data = train_X_data)
train_Y <- train_X_data$average_daily_rate
validation_X_matrix <- model.matrix(average_daily_rate ~. -1, data = validation_X_data)
validation_Y <- validation_X_data$average_daily_rate
```
The model i use, it is just a simple single layer model for testing.
# 1) single layer model structure
# step 1 make architecture powerful enough
modnn <- keras_model_sequential() %>%
layer_dense(units = 500, activation = "relu",
input_shape = ncol(train_X)) %>%
layer_dense(units = 1)
summary(modnn)
modnn %>% compile(loss = "mse",
optimizer = optimizer_rmsprop(),
metrics = list("mean_absolute_error"))
The error occurs after running the first epoch. I tought it was because the model could not read the names of the columns, but i tried a lot of things and nothing seemed to work.
Does anyone have an idea on how to fix this?
I cannot get the TensorBoard to open using RStudio and Keras package.
I am trying to duplicate the TensorBoard using the Keras package with R Studio as shown here: https://tensorflow.rstudio.com/tools/tensorboard/tensorboard/
Either I have a problem or I don't understand what needs to be done.
I am using these instructions:
# launch TensorBoard (data won't show up until after the first epoch)
tensorboard("logs/run_a")
# fit the model with the TensorBoard callback
history <- model %>% fit(
x_train, y_train,
batch_size = batch_size,
epochs = epochs,
verbose = 1,
callbacks = callback_tensorboard("logs/run_a"),
validation_split = 0.2
)
I get this error after running tensorboard("logs/run_a"):
> tensorboard("logs/run_a")
Error in if (tensorboard_version() < "2.0") { :
argument is of length zero
I have tried these versions:
tensorboard("/Users/kevinwilliams/Documents/r-studio-and-git/MNIST/logs/run_a")
tensorboard("logs/run_a")
tensorboard(log_dir = "logs/run_a")
tensorboard(log_dir = "logs/run_a", launch_browser = TRUE)`
The TensorBoard will not open.
The files structure of "logs" and "logs/run_a" was automatically created by these commands.
Training and Validation "events" are being saved to the file locations.
"fitting" the model does run and execute with no error. The output is sent to the RStudio Viewer and not to the TensorBoard.
Keras V2.7.0
RStudio 1.4.1717
R 4.1.1
It is just a file logging me even plots with matlibplot 👈👈👈
plt.plot(history.history['accuracy'], label='accuracy')
plt.plot(history.history['val_accuracy'], label = 'val_accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.ylim([0, 1]) # 0.5 - 1
plt.legend(loc='lower right')
Can you see there is some logging generated at target folder where you specific or checkpoints when you read it.?
Only using a tf.profile services to communicate with sub-services they already listening.
options = tf.profiler.experimental.ProfilerOptions(host_tracer_level = 3,
python_tracer_level = 1, device_tracer_level = 1)
tf.profiler.experimental.start(log_dir, options = options)
tf.profiler.experimental.server.start(6009)
tf.profiler.experimental.stop()
I have a couple of questions about a statefull cuDNN LSTM model I'm trying to fit in R using keras library. I have tensorflow-gpu installed and it seems to be running sucessfully.
The first thing I'm wondering about is the speed of model training which only seems to increase by a factor 1.3 using cuDNN lstm instead of ordinary LSTM. I have read other cases where people got models that train 10 or even 15 times faster when using cudnn lstm compared to normal lstm. I will post some code below.
Moreover I'm wondering about the percentage of memory usage of GPU. When code is run, it only seems to take roughly 8 % of GPU memory which seems a bit low. Can this be connected with the lack of increased speed.
dim(x.train) = (208, 1, 4)
dim(y.train) = (208 , 1)
For validation sets its the same except tat 208 is replaced with 42.
batch_size = 1
model <- keras_model_sequential()
model %>% layer_cudnn_lstm(units = 1, batch_input_shape = c(1,1,4),
stateful = TRUE, return_sequences = FALSE) %>%
layer_dropout(rate = dropout) %>%
layer_dense(units = 0.01)
model %>% compile(
loss = 'mean_squared_error',
optimizer = optimizer_adam(lr= 0.01, decay = 1e-8),
metrics = c('mean_squared_error')
)
Epochs <- 500
hist_temp <- model %>% fit(x.train, y.train, epochs=1, batch_size=batch_size, verbose=1, shuffle=FALSE,
validation_data = list(x.train_val, y.test))
model %>% reset_states()
Im expecting it to be much faster and more demanding on the GPU memory. What have I missed here?
this could have multiple reasons for example:
You have created a bottleneck while reading the data. You should check the cpu, memory and disk usage. Also you can increase the batche-size to maybe increase the GPU usage, but you have a rather small sample size. Morover a batch-size of 1 isn't realy common;)
2.You have a very small network so that you don't profit from GPU accleration as much. You can try to increase the size of the network to test if the GPU usage increases.
I hope this helps.
I'm following the example here: https://keras.rstudio.com/articles/examples/lstm_text_generation.html
I'm struggling to figure out how to save the model and then at a later date continue training (possibly on a different computer).
thanks!
in keras save your model architecture and weights.
then again every time to load and fit model with your new input datasets.
like this way.
from keras.layers import SimpleRNN, TimeDistributed
model=Sequential()
model.add(SimpleRNN(input_shape=(None, 2),
return_sequences=True,
units=5))
model.add(TimeDistributed(Dense(activation='sigmoid', units=3)))
model.compile(loss = 'mse', optimizer = 'rmsprop')
model.fit(inputs, outputs, epochs = 500, batch_size = 32)
model.save('my_model.h5')
from keras.models import load_model
model = load_model('my_model.h5')
# continue fitting
model.fit(inputs, outputs, epochs = 500, batch_size = 32)
I am running keras library from R under eclipse / statET / windows 10. After to fit a model, I am trying to run the following code:
history <- model %>% fit_generator(train_generator, steps_per_epoch = 100, epochs = 30, validation_data = validation_generator, validation_steps = 50)
jpeg(filename="figuras/history.jpg")
plot(history)
dev.off()
But no figure is drawn. Nevertheless, if I execute the same sententes above shown in the command line of statET, or I run the whole script from R, it works fine: could someone explain such behaviour?