Replicating tensorflow bert model in R - r

I am just replicating this code based on Basic Text Classification. Until the below line, it seems alright. However, the following line:
vectorize_layer %>% adapt(train_text)
throws me an error as below. Any idea, how should I approach it in order to solve it ? My tensorflow version is TensorFlow v2.8.2, is it the main issue for this error ?
I assume that the train_text should not be like that as well, should it ?
> train_text
<MapDataset element_spec=TensorSpec(shape=(None,), dtype=tf.string, name=None)>
The thrown error:
Error in py_call_impl(callable, dots$args, dots$keywords) :
RuntimeError: in user code:
File "C:\ANACON~2\envs\R-TENS~1\lib\site-packages\keras\engine\base_preprocessing_layer.py", line 118, in adapt_step *
self.update_state(data)
File "C:\ANACON~2\envs\R-TENS~1\lib\site-packages\keras\layers\preprocessing\text_vectorization.py", line 431, in update_state **
self._lookup_layer.update_state(self._preprocess(data))
File "C:\ANACON~2\envs\R-TENS~1\lib\site-packages\keras\layers\preprocessing\text_vectorization.py", line 512, in _preprocess
inputs = self._standardize(inputs)
File "C:\Users\xxxxx\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\call.py", line 21, in python_function
raise RuntimeError(res[kErrorKey])
RuntimeError: Evaluation error: attempt to apply non-function.

Related

How can I load a keras model into a Rmarkdown file and predict within the knitr?

I am trying to generate a plot of predictions with a previously trained model using keras tensoflow.
I use a chunk to try to load the model saved with the function:
save_model_hdf5()
this is saved in a R script separate from the Rmd file.
Once i have the model, I try to load it inside a chunk from the Rmarkdown file so I can use it to produce a plot of predictions:
```{r}
model_h <- load_model_hdf5("pogen/investigacions/modelo_keras/modelo_regresion/model_upto_2019.h5")
model_h %>% summary()```
When I click knit, the following error appears:
Error in py_call_impl(callable, dots$args, dots$keywords) :
OSError: SavedModel file does not exist at: pogen/investigacions/modelo_keras/modelo_regresion/model_upto_2019.h5/{saved_model.pbtxt|saved_model.pb}
Detailed traceback:
File "/home/ariel/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/tensorflow/python/keras/saving/save.py", line 189, in load_model
loader_impl.parse_saved_model(filepath)
File "/home/ariel/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/tensorflow/python/saved_model/loader_impl.py", line 113, in parse_saved_model
constants.SAVED_MODEL_FILENAME_PB))
Calls: <Anonymous> ... load_model -> do.call -> <Anonymous> -> py_call_impl
Execution halted
I don't know if someone has encountered this error before that could guide me towards finding a solution.

Trouble downloading Keras resnet50 model in R

I'm trying to download the ResNet50 model from Keras in R using the following code
model_resnet <- application_resnet50(weights = 'imagenet')
The code runs for a few seconds and doesn't give any error, however rather than being a 'Model' class like other Keras models, it saves as the following class:
<tensorflow.python.keras.engine.training.Model>
I can't predict anything from it or print it's summary or anything. I have the same issue if I try and run the example code from the ?application_resnet50 help page in R.
Does anyone know what this means?
R 3.5.1,
Keras 2.2.2,
Tensorflow 1.11.0
We're following the code from tensorflow rstudio and using R 3.5.1, Keras 2.2.2, Tensorflow 1.11.0
Basically, it is working as expected. The code runs for a few seconds and if all goes right, you end up with
<tensorflow.python.keras.engine.training.Model>
It is a Model, as it says. If things don't go right, this is what is being attempted, and here a network failure:
> library(keras)
> library(tensorflow)
> model_resnet50 <- application_resnet50()
Error in py_call_impl(callable, dots$args, dots$keywords) :
RemoteDisconnected: Remote end closed connection without response
Then is works:
> model_resnet50 <- application_resnet50(weights = 'imagenet')
Downloading data from https://github.com/fchollet/deep-learning- models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels.h5
Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels.h5
102858752/102853048 [==============================] - 14s 0us/step
2018-09-30 18:20:12.316814: I
tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports
instructions that this TensorFlow binary was not compiled to use:
SSE4.1 SSE4.2
> model_resnet50
<tensorflow.python.keras.engine.training.Model>
The next part depends on where those/that elephant jpeg are or come from,
it isn't clear from the link above, though probably from image-net.org.
Anyway, absent an "elephant.jpg" in your working directory, you get:
> img_path <- "elephant.jpg"
> img <- image_load(img_path, target_size = c(224,224))
Error in py_call_impl(callable, dots$args, dots$keywords) :
FileNotFoundError: [Errno 2] No such file or directory:
'elephant.jpg'
Get some elephant jpegs and continue following the examples and have fun.

Can't load truncated images keras generator in r

Getting the error below trying to train the output layers of a model that uses inceptionV3.
Flow_from_directory generator works fine but when i try and train the model (weights are freezer, only training final layers) this error pops up:
Error in py_call_impl(callable, dots$args, dots$keywords) :
StopIteration: image file is truncated (49 bytes not processed)
In Python i know how to solve the problem, just use the code below:
from PIL import Image
ImageFile.LOAD_TRUNCATED_IMAGES = True
What about in R?
Thanks
library(reticulate)
PIL <- import("PIL")
PIL$ImageFile$LOAD_TRUNCATED_IMAGES <- TRUE
quote from github

Error using DEXSeqDataSetFromHTSeq

Currently I am trying to understand DEXSeq package. I have a design tsv file and 7 files which contains Counts. Now would like to run the following command
library("DEXSeq");
design=read.table("dexseq_design.tsv", header=TRUE, row.names=1);
ecs = DEXSeqDataSetFromHTSeq(countfiles=c("M0.txt", "M1.txt", "M2.txt", "M3.txt", "M4.txt", "M5.txt", "M6.txt", "M7.txt"), design=design, flattenedfile="genome.chr.gff");
The last command gives and error
Error in class(sampleData) %in% c("data.frame") :
error in evaluating the argument 'x' in selecting a method for function '%in%':
Error: argument "sampleData" is missing, with no default
What does this error means and how to fix it? While loading the package DEXSeq there was a warning
Warning message:
replacing previous import by ‘ggplot2::Position’ when loading ‘DESeq2’

methylSigCalc function error

Trying to use the latest version of methylSig package (0.3.2), and getting an error when using the methylSigCalc function.
I get a cryptic error message after it figures out the number of loci:
Total number of bases: 2.59m
Error in result[, 3] : subscript out of bounds”
I tried running the code of the methylSigCalc function line by line, and the first error I encounter is when it gets to the methylSig_dataProcess function (below is the error after specifying just one core to try to get a useful error message):
Error in do.call(rbind, lapply(which(validLoci),
methylSig_dataProcess, : error in evaluating the argument 'args' in
selecting a method for function 'do.call': Error in match.fun(FUN) :
object 'methylSig_dataProcess' not found
It does seem that methylSig_dataProcess is now missing from the package.
Any suggestions on where I might be going wrong?
Many thanks,
gogatea

Resources