Cannot get Tensorboard visualization tool to open - r

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()

Related

Why does running the tutorial example fail with Rstan?

I installed the RStan successfully, the library loads. I try to run a tutorial example (https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started#example-1-eight-schools). After applying the stan function
fit1 <- stan(
file = "schools.stan", # Stan program
data = schools_data, # named list of data
chains = 4, # number of Markov chains
warmup = 1000, # number of warmup iterations per chain
iter = 2000, # total number of iterations per chain
cores = 1, # number of cores (could use one per chain)
refresh = 0 # no progress shown
)
I get the following error:
*Error in compileCode(f, code, language = language, verbose = verbose) :
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file1c34165764a4.o:file1c34165764a4.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file1c34165764a4.o:file1c34165764a4.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file1c34165764a4.o:file1c34165764a4.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file1c34165764a4.o:file1c34165764a4.cpp:(.text$_ZN3tbb10interface
Error in sink(type = "output") : invalid connection*
Simply running example(stan_model, run.dontrun=T) gives the same error.
What does this error mean?
Is rtools wrongly installed? My PATH seems to contain the correct folder C:\\rtools42\\x86_64-w64-mingw32.static.posix\\bin;. Is something wrong with the version of my Rstan package? I am struggling to interpret this error?
What to try to solve it?
Apparently Rtools42 in incompatible with the current version Rstan on CRAN. The solution that worked for me is found here: https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Windows#r-42

executing keras CNN models keeps crashing my computer

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.

plot() does not work with keras, eclipse and statET

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?

Tree splits in a H2o GBM Model

By running the commands,
m <- h2o.getModel("depth_grid_model_4")
h2o.varimp(m)
I am able to view the model's performance as well as the variable importance.
How do I view the splits used in each tree of the GBM model?
Thanks
There is a tool to create visualizations for H2O-3 MOJO models. See the full documentation here:
http://docs.h2o.ai/h2o/latest-stable/h2o-genmodel/javadoc/overview-summary.html#viewing-a-mojo
Use R to create and download a MOJO:
library(h2o)
h2o.init()
df <- h2o.importFile("http://s3.amazonaws.com/h2o-public-test-data/smalldata/airlines/allyears2k_headers.zip")
model <- h2o.gbm(model_id = "model",
training_frame = df,
x = c("Year", "Month", "DayofMonth", "DayOfWeek", "UniqueCarrier"),
y = "IsDepDelayed",
max_depth = 3,
ntrees = 5)
h2o.download_mojo(model, getwd(), FALSE)
Run the PrintMojo tool (packaged inside h2o.jar) on the command line to make a .png file. You need to download the latest stable H2O-3 release from http://www.h2o.ai/download/ and run the PrintMojo tool from the command line.
# (For MacOS: brew install graphviz)
java -cp h2o.jar hex.genmodel.tools.PrintMojo --tree 0 -i model.zip -o model.gv
dot -Tpng model.gv -o model.png
open model.png
New Tree API was added in H2O in 3.22.0.1. It lets you fetch trees into R/Python objects from any tree-based model in H2O (for details see here):
tree <- h2o.getModelTree(model = airlines.model, tree_number = 1, tree_class = "NO")
Having a tree representation from h2o in R plotting a tree explained here: Finally, You Can Plot H2O Decision Trees in R
You can export the model as POJO with h2o.download_pojo() and then look at the full details of each tree in the file.

Error in R h2o.predict with xgboost -> java.lang.NullPointerException

First of all thanks for implementing XGBoost in h2o!
Unfortunately I am unable to predict from an h2o xgboost model that's loaded from disk (which I'm sure you can appreciate is really frustrating).
I am using the latest stable release of h2o i.e. 3.10.5.2 & I am using an R client.
I have included an example below that should enable you to reproduce the issue,
Thanks in advance
### Start h2o
require(h2o)
local_h2o = h2o.init()
### Source the base data set
data(mtcars)
h2o_mtcars = as.h2o(x = mtcars,destination_frame = 'h2o_mtcars')
### Fit a model to be saved
mdl_to_save = h2o.xgboost(model_id = 'mdl_to_save',y = 1,x = 2:11,training_frame = h2o_mtcars) ##This class doesnt work
#mdl_to_save = h2o.glm(model_id = 'mdl_to_save',y = 1,x = 2:11,training_frame = h2o_mtcars) ##This class works
### Take some reference predictions
ref_preds = h2o.predict(object = mdl_to_save,newdata = h2o_mtcars)
### Save the model to disk
silent = h2o.saveModel(object = mdl_to_save,path = 'INSERT_PATH',force = TRUE)
### Delete the model to make sure there cant be any strange locking issues
h2o.rm(ids = 'mdl_to_save')
### Load it back up
loaded_mdl = h2o.loadModel(path = 'INSERT_PATH/mdl_to_save')
### Score the model
### The h2o.predict statement below is what causes the error: java.lang.NullPointerException
lod_preds = h2o.predict(object = loaded_mdl,newdata = h2o_mtcars)
all.equal(ref_preds,lod_preds)
At the time I write this (January 2018), this is still a bug for xgboost. See this ticket for more information.
In the meantime, you can download the model as a pojo or mojo file
h2o.download_pojo(model, path = "/media/somewhere/tmp")
Loading the model back isn't that easy, unfortunately, but you can pass the new data via json to the saved pojo model with the function:
h2o.predict_json()
However, the new data must be provided in json format.
See this question for more details

Resources