eagerai / fastai Goto Github PK
View Code? Open in Web Editor NEWR interface to fast.ai
Home Page: https://eagerai.github.io/fastai/
License: Apache License 2.0
R interface to fast.ai
Home Page: https://eagerai.github.io/fastai/
License: Apache License 2.0
Hi,
I receive the following error when I try to download the data using URLs_ADULT_SAMPLE().
Error: $ operator is invalid for atomic vectors
Can somebody please assist
Hi again.
Running the following :
path_img = 'cassava-leaf-disease-classification/train_images/'
#library(data.table)
labels<-read_csv('cassava-leaf-disease-classification//train.csv')
head(labels)
dataloader <- fastai::ImageDataLoaders_from_df(df=labels, path=path_img, bs=8, seed=6,
num_workers=0,
item_tfms = Resize(448),
batch_tfms = aug_transforms(size=224, min_scale=0.75))
dataloader %>% show_batch()
learnR <- dataloader %>% cnn_learner(xresnet50(), metrics = accuracy, model_dir="fastai_model/") #prettier
learnR$to_fp16()
learnR$freeze()
learnR %>% lr_find()
learnR %>% plot_lr_find(dpi = 200)
I can knit and got a md document with the graphs. However, running the cells of the rmarkdown document will not output anything below the line Or inside the plots panels. (while it will happen with keras for example).
I do not know for sure if this is a local config problem, or a change introduced by the commit 8594699.
bs_find for tabular data does not work with fast.ai==2.2.7:
Message: KeyError: "None of ['n_iter'] are in the columns"
Detailed traceback:
File "D:\a\fastai\fastai\check\fastai.Rcheck\fastai\python\fastaibuilt\bs_finder.py", line 161, in bs_find
with self.no_logging(): self.fit(n_epoch, lr, cbs=cb)
File "C:\Users\RUNNER~1\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\fastai\learner.py", line 211, in fit
self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)
File "C:\Users\RUNNER~1\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\fastai\learner.py", line 162, in _with_events
self(f'after_{event_type}'); final()
File "C:\Users\RUNNER~1\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\fastai\learner.py", line 141, in __call__
def __call__(self, event_name): L(event_name).map(self._call_one)
File "C:\Users\RUNNER~1\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\fastcore\foundation.py", line 154, in map
def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
File "C:\Users\RUNNER~1\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\fastcore\basics.py", line 666, in map_ex
return list(res)
File "C:\Users\RUNNER~1\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\fastcore\basics.py", line 651, in __call__
return self.func(*fargs, **kwargs)
File "C:\Users\RUNNER~1\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\fastai\learner.py", line 145, in _call_one
for cb in self.cbs.sorted('order'): cb(event_name)
File "C:\Users\RUNNER~1\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\fastai\callback\core.py", line 44, in __call__
if self.run and _run: res = getattr(self, event_name, noop)()
File "D:\a\fastai\fastai\check\fastai.Rcheck\fastai\python\fastaibuilt\bs_finder.py", line 126, in after_fit
df.set_index('n_iter', inplace=True)
File "C:\Users\RUNNER~1\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\pandas\core\frame.py", line 4727, in set_index
raise KeyError(f"None of {missing} are in the columns")
Please briefly describe your problem and what output you expect.
I got the following error when trying to install the fastai package using r.
I think it wants to convince me to purchase Microsoft Visual C++ 14.0, but that is not in my budget. I'm still paying off my student loans. (@michael Nikkhoo)
My command was:
fastai::install_fastai(gpu = FALSE, cuda_version = '10.1', overwrite = FALSE)
There was a ton of text and then this error in the middle:
copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.6\pycocotools
copying pycocotools\mask.py -> build\lib.win-amd64-3.6\pycocotools
copying pycocotools\__init__.py -> build\lib.win-amd64-3.6\pycocotools
running build_ext
skipping 'pycocotools\_mask.c' Cython extension (up-to-date)
building 'pycocotools._mask' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
----------------------------------------
Then it gave me this as the final result:
ERROR: Command errored out with exit status 1: 'C:\Users\<username>\AppData\Local\R-MINI~1\envs\R-RETI~1\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\<username>\\AppData\\Local\\Temp\\pip-install-hbabtz_i\\pycocotools_88fb2b1f63764ff4b73954ac6b86a7da\\setup.py'"'"'; __file__='"'"'C:\\Users\\<username>\\AppData\\Local\\Temp\\pip-install-hbabtz_i\\pycocotools_88fb2b1f63764ff4b73954ac6b86a7da\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\<username>\AppData\Local\Temp\pip-record-64h7kl2e\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\<username>\AppData\Local\R-MINI~1\envs\R-RETI~1\Include\pycocotools' Check the logs for full command output.
Error: Error installing package(s): "torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html", "IPython", "fastai==2.1.5", "pydicom", "kornia", "opencv-python", "scikit-image", "kaggle", "transformers", "timm", "fastinference[interp]", "ohmeow-blurr", "icevision[all]", "git+https://github.com/tcapelle/timeseries_fastai.git", "git+https://github.com/tmabraham/UPIT.git", "opencv-python-headless==4.4.0.46"
Of course, usernames have been changed to protect the innocent...
fast.ai for Mac OS installs first torch 1.8 then 1.7.1. We need to install pkgs separately, so unnecessary installation will not be required. First, install fastai (try).
Core callbacks are not implemented from the R side:
Hi. I am not sure why but I got trouble running TextBlock_from_df().
I have a data.table looking like the following :
Id | text_article | label
d0fa7568-7d8e-4db9-870f-f9c6f668c17b | What is this study about? This study used data from the National Education Longitudinal Study (NELS:88) to examine the effects of dual enrollment programs for high school students on college degree attainment | national education longitudinal study
I am trying to run :
data_block = DataBlock(
blocks = list(TextBlock_from_df(text_cols="text_article")), #List() is required on the R side.
get_x=ColReader("text_article"),
get_y=ColReader('label'))
According to the example here https://docs.fast.ai/text.data.html#TextBlock.from_df and here : https://github.com/EagerAI/fastai#text-data and the fastai books.
But I also tried directly :
data_block = DataBlock(blocks = list(TextBlock_from_df(text_cols="text_article"))) #from fastai doc
Both gave me the following error :
Error: $ operator is invalid for atomic vectors
Traceback:
- DataBlock(blocks = list(TextBlock_from_df(text_cols = "text_article")))
- TextBlock_from_df(text_cols = "text_article")
- do.call(text()$TextBlock$from_df, args)
I put in bold what attract my suspicion. I am not really at home here, I am doing NLP with fastai for the first time, both in R and fastai as well.
I am putting the name of the column directly as a string, "text_article" as I am supposed to do. Based on the examples the dataframe with the text is supposed to be provided after. For what I understand the fastai wrapper is not happy about the text()$TextBlock$from_df).
We could add auto ml for tabular data like in h2o.automl
.
Fix all the issues and submit fastai 2.1.5.
2.1.8 has a lot of bugs:
Hugging face for fastai. In addition, please add an example!
Works for Mac and Linux!
We need to add the object detection Icevision https://github.com/airctic/icevision for fast.ai
from R.
Breaking changes since fastai >= 2.1 which requires torch >= 1.7. Needs to be fixed.
When training a model like in this notebook or here (md doc to got the session infos).
I got the following error from python :
Quitting from lines 106-107 (Bug_method_export.Rmd)
Error in py_call_impl(callable, dots$args, dots$keywords) :
AttributeError: Can't pickle local object 'make_python_function.<locals>.python_function'
Detailed traceback:
File "/home/erolland/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/fastai/learner.py", line 542, in export
torch.save(self, self.path/fname, pickle_protocol=pickle_protocol)
File "/home/erolland/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/torch/serialization.py", line 372, in save
_save(obj, opened_zipfile, pickle_module, pickle_protocol)
File "/home/erolland/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/torch/serialization.py", line 476, in _save
pickler.dump(obj)
Calls: <Anonymous> ... withVisible -> eval -> eval -> <Anonymous> -> py_call_impl
Exécution arrêtée
When I am running :
learnR$export(fname = export.pkl)
The error message came from the first notebook. The second md document provide the session infos().
Hi,
I tried to run the tabular learner from rstudio. Running procs = list(FillMissing(),Categorify(),Normalize()), I get the following error: Error: $ operator is invalid for atomic vectors. Is there a fix for that? Thanks.
fastaudio causes an issue while installing in Windows.
If !os=="linux", num_workers always == 0. Fix for all data loaders, e.g. image laoders
If cuda is available place it to cuda
.
Example:
Data_Loaders(train_dl, valid_dl)
Fix Github Actions for the dev version of fast.ai (Github version)
Data loaders with num_workers
arguments have to be set by default to 0L
for Windows.
Hi there,
Thanks for great work to bring fastai to R.
In step two, after installing fastai from git hub, I am getting the following error when I try to load the library.
devtools::install_github('henry090/fastai')
library(fastai)
Error: package or namespace load failed for ‘fastai’ in get(method, envir = envir):
lazy-load database 'C:/R-libraries/fastai/R/fastai.rdb' is corrupt
In addition: Warning message:
In get(method, envir = envir) : internal error -3 in R_decompress1
Any help to get around this would be much appreciated.
Many thanks,
Mubashir
Download zebra/horse video from youtube. With magick
extract frames. And, finally, train the model.
@henry090 I just realized that some models are missing from fastai :
https://docs.fast.ai/vision.models.xresnet.html
Namely all the models such as xse_resnext50.
I could add them too if you don't mind.
Can we make the installation of fast.ai prettier? e.g:
PyTorch installed successfully (1.7.1)
Fast.ai installed successfully (2.2.7)
In case of error, try-catch and return them for debugging.
At the end print the python path, so the user can figure out which python was used for installation.
Is it possible somehow to work on Colab from RStudio? (GPU)
Hi,
I was thinking on the how to train xse-resnext-50 in R without going out of memory. Huge networks like this seems to be trained in Pytorch using TPU on Kaggle.
Fastai does not handle directly TPU but there is some wrapper : https://github.com/butchland/fastai_xla_extensions
Example here : https://www.kaggle.com/johnyquest/tpu-fastai-notebook
I put this as a feature request and a reminder to myself to look into this. As far as I can see it does not seems to much difficult to use TPU with fastai (four pip install and a methods on the learner).
But I don't have your experience with the wrapper/TPU (As far as I know you are the only person that created a kernel with TPU inside R on kaggle :p )
Is it as "easy" as it seems or is there a problem I do not see ?
I am using this tutorial for super resolution Unet model. https://cran.r-project.org/web/packages/fastai/vignettes/super_res_gan.html. However, the create_gen_learner
function resulted in Error in py_get_attr_impl(x, name, silent) : AttributeError: module 'fastai.vision.gan' has no attribute 'unet_config'
error. The basic Unet without unet_config
argument works fine. https://github.com/henry090/fastai#unet-example
create_gen_learner = function() {
unet_learner(dls_gen, arch, loss_func = loss_gen,
config = unet_config(blur=TRUE, norm_type = "Weight",
self_attention = TRUE, y_range = y_range))
}
learn_gen = create_gen_learner()
# Error in py_get_attr_impl(x, name, silent) :
# AttributeError: module 'fastai.vision.gan' has no attribute 'unet_config'
Python wrapper functions definition issue. rstudio/reticulate#869
fastai2 = reticulate::import('fastai')
Mnist_Logistic <- reticulate::PyClass(
classname = 'Mnist_Logistic',
inherit = fastai2$basics$Module,
list(
`__init__` = function(self) {
self$lin = fastai2$basics$nn$Linear(784L, 10L, bias = TRUE)
NULL
},
forward = function(self, xb) {
self$lin(xb)
}
)
)
Error in py_call_impl(callable, dots$args, dots$keywords) :
KeyError: 'self'
Detailed traceback:
File "/Users/turgutabdullayev/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/fastcore/meta.py", line 28, in __new__
if res.__init__ is not object.__init__: res.__signature__ = _rm_self(inspect.signature(res.__init__))
File "/Users/turgutabdullayev/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/fastcore/meta.py", line 20, in _rm_self
sigd.pop('self')
We need to have examples for:
I am not 100 % sure it is a bug.
Running code from here : https://github.com/Cdk29/Cassava/blob/main/Xresnet.md
Particularly :
I create the learner using :
learnR <- dataloader %>% cnn_learner(xresnet50(), metrics = accuracy(), model_dir="Xresnet_files/") #prettier
But fastai export it elsewhere :
erolland@erolland-GL75-9SE:~/Bureau$ locate xresnet_50.pkl
/home/erolland/Bureau/Cassava/cassava-leaf-disease-classification/train_images/xresnet_50.pkl
I am not sure but I don't think it is the normal behavior of the export of fastai to use the directory of the training set and not the model_dir to export its model.
We need to add a TPU example on Colab. Then add a ref link to the readme file
No more custom installation of fast audio and other minor issues.
Add Bayesian Optimization tutorial with fast.ai
We could add auto ml for tabular data like in h2o
.
A lot of examples need to be added for NLP:
How to slice tensors from R?
Thank you very much for an awesome and much needed package. I'm saving a model after each epoch using SaveModelCallback
nb_epoch <- 8
learn %>% fit_one_cycle(nb_epoch, cbs = SaveModelCallback(every_epoch = TRUE, fname = 'model'))
Say I'm using a new session, and that I'd like to start from the latest model. Is there a way to load this last model with extension .pth that I stored previously? I guess my question is related to issue #115 I've just seen.
Thanks in advance.
Cannot print the summary of vision models. Throws error.
@henry090 Last commit introduced the suppression of inst/python/fastaibuilt/pycache/bs_finder.cpython-36.pyc.
I was getting a merging error because of this file, I though I merged the new one of the henry090 / fastai master branch here in my fork.
I do not know how this file is generated in the first place. Maybe you should check after it.
Edit : looking at my history I did git rm on this file to try to solve the merging error. That was quite stupid, sorry for that. I just that just re indexing the file on your local folder will do the trix.
@henry090 : I am trying to train a xse_resnet50.
During training I got the following error :
R: /opt/conda/conda-bld/magma-cuda101_1583546950098/work/interface_cuda/interface.cpp:901: void magma_queue_create_from_cuda_internal(magma_device_t, cudaStream_t, cublasHandle_t, cusparseHandle_t, magma_queue**, const char*, const char*, int): Assertion `queue->dCarray__ != __null' failed.
It is not a simple out of memory error, it seems to be some kind of memory leak related to magma, similar to related here.
But : I did not find any mention of this bug occurring with fastai, which I would have expect if this thing occurred recurrently, except for this message on this thread : https://forums.fast.ai/t/a-walk-with-fastai2-vision-study-group-and-online-lectures-megathread/59929/1293 :
The only “new” thing I am doing is that I am encapsulating most of my code for training the model in a try/except block in a while loop.
I wonder if the memory leak is not somehow due to using a function as a wrapper or reticulate.
Link towards the code and error : https://www.kaggle.com/cdk292/magma-error-xse-resnext50-with-r?scriptVersionId=50229515
The last version is still compiling but you can see in the log of execution of version 4 the error, and will probably shown up again in V6.
PS : merry Christmas.
If the argument in the list is null remove it. For example
args = list(length=NULL)
if(is.null(args$length)) {
args$length <- NULL
}
Hello, I followed this tutorial: https://henry090.github.io/fastai/articles/multilabel.html
And hit an error when I ran this line: learn %>% summary()
Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: not enough values to unpack (expected 5, got 4)
Detailed traceback:
File "/mnt/hdd/Z_NLP_Classifier/07_Test_03/02_Code/renv/python/r-reticulate/lib/python3.6/site-packages/blurr/modeling/core.py", line 120, in blurr_summary
res = blurr_module_summary(self, *xb)
File "/mnt/hdd/Z_NLP_Classifier/07_Test_03/02_Code/renv/python/r-reticulate/lib/python3.6/site-packages/blurr/modeling/core.py", line 98, in blurr_module_summary
for typ,np,trn,sz,chnged in infos:
Lastly, not sure if this is relevant, I modified the creation of blocks to be the following (whilst tutorial only include hf_arch and hf_tokenizer):
blocks = list(
HF_TextBlock(hf_arch, hf_config, hf_tokenizer, hf_model),
MultiCategoryBlock(encoded=TRUE, vocab=lbl_cols))
Thank you very much in advance!
We need tests for:
install_fastai
Basic tests are enough for now.
Can we make the model training interactive in Colab. Image plotting is not good.
Thanks again for doing this package. Since you seem to use Kaggle notebooks yourself, do you know what's up with the installed R package that is now part of the standard R Kaggle set-up? I tried a few things and just could not get it to work. It looks to me like the python fastai
package is missing in the background (I also posted this on Kaggle), but my attempt to simply use fastai::install_fastai(gpu = FALSE, cuda_version = '10.1', overwrite = FALSE)
failed. Do you know how to get this to work (great if you could share that)? I would of course also understand if you feel that fixing Kaggle's setup is not your problem.
There is one callback describe here : https://docs.fast.ai/callback.fp16.html
Details here : https://docs.fast.ai/callback.fp16.html#Learner.to_fp16
It allow to use less GPU when training a CNN.
The book describe the use of the method when creating the learner, but it can also be used on the learner directly.
Running it in R however create a bug, and I don't see how to use it.
Precisely :
learnR <- dataloader %>% cnn_learner(xresnet50(), metrics = accuracy, model_dir="fastai_model/") #prettier
learnR$to_fp16()
Then running :
learnR %>% lr_find()
Error in py_call_impl(callable, dots$args, dots$keywords) : AttributeError: 'str' object has no attribute 'type'`
Because now the learner is a string.
load_learner() is the function that allow to load a model that has been exported. It does not seems to exist in the wrapper :
dice loss & feature loss, but a general way to customize the loss function will be better. https://github.com/fastai/fastai/blob/master/dev_nbs/course/lesson7-superres.ipynb https://kaggle.com/bigironsphere/loss-function-library-keras-pytorch
Allow NLP module installation only for Linux
dicom test does not work with fast.ai==2.2.7:
Message: RuntimeError: Given groups=1, weight of size [64, 3, 7, 7], expected input[1, 1, 224, 224] to have 3 channels, but got 1 channels instead
Detailed traceback:
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/fastai/learner.py", line 243, in get_preds
self._do_epoch_validate(dl=dl)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/fastai/learner.py", line 193, in _do_epoch_validate
with torch.no_grad(): self._with_events(self.all_batches, 'validate', CancelValidException)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/fastai/learner.py", line 160, in _with_events
try: self(f'before_{event_type}'); f()
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/fastai/learner.py", line 166, in all_batches
for o in enumerate(self.dl): self.one_batch(*o)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/fastai/learner.py", line 184, in one_batch
self._with_events(self._do_one_batch, 'batch', CancelBatchException)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/fastai/learner.py", line 160, in _with_events
try: self(f'before_{event_type}'); f()
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/fastai/learner.py", line 169, in _do_one_batch
self.pred = self.model(*self.xb)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/torch/nn/modules/container.py", line 117, in forward
input = module(input)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/torch/nn/modules/container.py", line 117, in forward
input = module(input)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/torch/nn/modules/conv.py", line 423, in forward
return self._conv_forward(input, self.weight)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/torch/nn/modules/conv.py", line 419, in _conv_forward
return F.conv2d(input, weight, self.bias, self.stride,
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/fastai/torch_core.py", line 329, in __torch_function__
res = super().__torch_function__(func, types, args=args, kwargs=kwargs)
File "/Users/runner/Library/r-miniconda/envs/r-reticulate/lib/python3.9/site-packages/torch/tensor.py", line 995, in __torch_function__
ret = func(*args, **kwargs)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.