Giter Club home page Giter Club logo

mlr3keras's Introduction

mlr3keras

An extension for mlr3 to enable using various keras models as learners.

tic

Status

mlr3keras is in very early stages, and currently under development. Functionality is therefore experimental and we do not guarantee correctness, safety or stability. It builds on top of the (awesome) R packages reticulate, tensorflow and keras. Comments, discussion and issues/bug reports and PR's are highly appreciated.

If you want to contribute, please propose / discuss adding functionality in an issue in order to avoid unnecessary or duplicate work.

Installation:

# Install from GitHub
remotes::install_github("mlr-org/mlr3keras")

Troubleshooting:

If you encounter problems using the correct python versions, see here.

mlr3keras is currently tested and works using the python packages keras (2.4) and tensorflow (2.3.1).

Setting up mlr3keras with anaconda

One possible workflow for working with mlr3keras is described below. While (1.) and (2.) are one-time setup steps, (3.) now has to be called everytime mlr3keras is loaded.

Note from the author: The workflow described below is something that works for me personally, as I have to switch between versions and projects often. It is described for the user, as I personally find it useful. It assumes, the R packages keras, tensorflow and reticulate are installed. In order to load mlr3keras I now have to execute an additional one additional line (see 3.), but version management is heavily simplified. Note, that this seems to work on Linux but has not been extensively tested on other systems.

  1. Install Miniconda (if not already installed)
# Execute and restart R afterwards
reticulate::install_miniconda()

NOTE: It might make sense, to set the RETICULATE_PYTHON environment variable to your miniconda / Anaconda installation path as explained here.

  1. Install a mlr3keras conda environment together with keras and tensorflow
# Execute and restart R afterwards
reticulate::conda_create(
  envname = "mlr3keras",
  packages = c("pandas", "python=3.8")
)
keras::install_keras("conda", tensorflow="2.3.1", envname="mlr3keras")
  1. Loading the mlr3keras package
reticulate::use_condaenv("mlr3keras")
library(mlr3keras)
  1. Installing a new package
conda_install("mlr3keras", packages = "tabnet", pip = TRUE)

Usage

mlr3keras currently exposes three Learners for regression and classification respectively.

Learner Details Reference
regr/classif.keras A generic wrapper that allows to supply a custom keras architecture as a hyperparameter. --
regr/classif.kerasFF A fully-connected feed-forward Neural Network with entity embeddings Guo et al. (2016) Entity Embeddings for Categorical Variables
regr/classif.tabNet An implementation of TabNet Sercan, A. and Pfister, T. (2019): TabNet
regr/classif.smlp Shaped MLP inspired by Configuration Space 1* Zimmer, L. et al. (2020): Auto PyTorch Tabular
regr/classif.smlp2 Shaped MLP inspired by Configuration Space 2* Zimmer, L. et al. (2020): Auto PyTorch Tabular
regr/classif.deep_wide Deep and Wide Architecture inspired by Ericson et al., 2020 AutoGluon-Tabular: Robust and Accurate AutoML for Structured Data
classif.kerascnn Various CNN Applications via Transfer-learning Uses keras::application_XXX (e.g. mobilenet)
  • with some slight changes, namely no Shake-Shake, Shake-Drop, Mixup Training. and added Entity Embeddings for categorical variables.

Learners can be used for training and prediction as follows:

  library("mlr3")
  # Instantiate Learner
  lrn = LearnerClassifKerasFF$new()

  # Set Learner Hyperparams
  lrn$param_set$values$epochs = 50
  lrn$param_set$values$layer_units = 12

  # Train and Predict
  lrn$train(tsk("iris"))
  lrn$predict(tsk("iris"))

The vignette has some examples on how to use some of the functionality introduces in mlr3keras.

Design

This package's purpose for now is to understand the design-decisions required to make keras \ tensorflow work with mlr3 and flexible enough for users.

Several design decisions are not made yet, so input is highly appreciated.

Current Design and Scope

Design

The goal of the project is to expose keras models as mlr3 learners. A keras model in this context should be understood as the combination of

  • model architecture:

    keras_model_sequential() %>%
    ... %>%
    layer_activation(...)
  • training procedure:

    model$compile(...)
    model$fit(...)
  • All hyperparameters that control the steps:

    • architecture hyperparams (dropout, neurons / filters, activation functions, ...)
    • optimizer choice and hyperparams (learning rate, ...)
    • fit hyperparams (epochs, callbacks, ...)

Some important caveats:

  • Architectures are often data-dependent, e.g. require correct number of input / output neurons. As a result, in mlr3keras, the architecture is a function of the incoming training data. In mlr3keras, this is abstracted via KerasArchitecture: See KerasArchitectureFF for an example. This Architecture is initialized with a build_arch_fun which given the task and a set of hyperparameters constructs & compiles the architecture.

  • Depending on the architecture, different data-formats are required for x (features) and y (target) (e.g. a matrix for a feed-forward NN, a list of features if we use embeddings, ...) To accomodate this, each architecture comes with an x_transform and a y_transform method, which are called on the features and target respectively before passing those on to fit(...).

Scope The current scope for mlr3keras is to support deep learning on different kinds of tabular data. In the future, we aim to extend this to other data modalities, but as of yet, work on this has not started.

In an initial version, we aim to support two types of models:

  • Pre-defined architectures: In many cases, we just want to try out and tune architectures that have already been successfully used in other contexts (LeNet, ResNet, TabNet). We aim to implement / make those accessible for simplified tuning and fast iteration. Example: LearnerClassifTabNet$new().

  • Fully custom architectures: Some operations require completely new architectures. We aim to allow users to supply custom architectures and tune hyperparameters of those. This can be done via KerasArchitectureCustom by providing a function that builds the model given a Task and a set of hyperparameters.

All architectures can be parametrized and tuned using the mlr3tuning library.

Open Issues:

  • Custom Optimizers / Losses / Activations
    • As keras and it's ecosystem is constantly growing, the interface needs to be flexible and highly adaptable. We try to solve this using a reflections mechanism: keras_reflections that stores possible values for exchangable parts of an architecture. New methods can now be added by adding to the respective reflection.
  • More data types:
    • Currently mlr3 does not support features such as images / audio / ..., therefore mlr3keras is not yet applicable for image classification and other related tasks. We aim to make this possible in the future! A minor road block here is to find a way to not read images to memory in R but directly load from disk to avoid additional overhead.
    • It is unclear how efficient data preprocessing for images etc. can be paired with mlr3pipelines, yet we hope this can be solved at some point in the future.
  • More task types:
    • Currently mlr3 focusses heavily on standard classification and regression. Many Deep Learning tasks require slight extensions (image annotation, bounding boxes, object detection, ... ) of those existing data containers (Task, Prediction, ...).

Installation

remotes::install_github("mlr-org/mlr3keras")

Resources

mlr3keras's People

Contributors

henrifnk avatar mllg avatar pat-s avatar pfistfl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jackyp henrifnk

mlr3keras's Issues

stacked TabNet doesn't seem to work

> library("mlr3")
> library("mlr3keras")
> learner <- lrn("regr.tabnet")
Loading required package: tensorflow
> learner$param_set$values$stacked <- TRUE
> learner$param_set$values$num_layers <- 2
> learner$train(tsk("boston_housing"))
[...]
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  AttributeError: in user code:

    /home/user/projects/genomenet/install/miniconda2/envs/py37/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:571 train_function  *
        outputs = self.distribute_strategy.run(
    /home/user/projects/genomenet/install/miniconda2/envs/py37/lib/python3.6/site-packages/tabnet/stacked_tabnet.py:351 call  *
        self.activations = self.tabnet(inputs, training=training)

    AttributeError: 'StackedTabNetRegressor' object has no attribute 'tabnet'


Detailed traceback: 
  File "/home/user/projects/genomenet/install/miniconda2/envs/py37/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 66, in _method_wrapper
    return method(self, *args, **kwargs)
  File "/home/user/projects/genomenet/install/miniconda2/envs/py37/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 848, in fit
    tmp_logs = train_function(iterator)
  File "/home/user/projects/genomenet/install/minicon

Error: Error installing package(s)

I was following steps for installation but got error:

> keras::install_keras("conda", tensorflow="2.3.1", envname="mlr3keras")
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done

## Package Plan ##

  environment location: C:\Users\Mislav\AppData\Local\R-MINI~1\envs\mlr3keras

  added / updated specs:
    - python=3.7


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    numpy-1.21.2               |   py37h940b05c_0         5.6 MB  conda-forge
    pandas-1.3.2               |   py37h9386db6_0        10.8 MB  conda-forge
    python-3.7.10              |h7840368_100_cpython        17.9 MB  conda-forge
    python_abi-3.7             |          2_cp37m           4 KB  conda-forge
    setuptools-58.0.4          |   py37h03978a9_0         927 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        35.2 MB

The following packages will be DOWNGRADED:

  numpy                               1.21.2-py38h089cfbf_0 --> 1.21.2-py37h940b05c_0
  pandas                               1.3.2-py38h5d928e2_0 --> 1.3.2-py37h9386db6_0
  python                          3.8.10-h7840368_1_cpython --> 3.7.10-h7840368_100_cpython
  python_abi                                     3.8-2_cp38 --> 3.7-2_cp37m
  setuptools                          58.0.4-py38haa244fe_0 --> 58.0.4-py37h03978a9_0



Downloading and Extracting Packages
numpy-1.21.2         | 5.6 MB    | ########## | 100% 
python_abi-3.7       | 4 KB      | ########## | 100% 
setuptools-58.0.4    | 927 KB    | ########## | 100% 
pandas-1.3.2         | 10.8 MB   | ########## | 100% 
python-3.7.10        | 17.9 MB   | ########## | 100% 
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/tensorflow/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/tensorflow/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/tensorflow/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/tensorflow/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/tensorflow/
Could not fetch URL https://pypi.org/simple/tensorflow/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/tensorflow/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement tensorflow==2.3.1.* (from versions: none)
ERROR: No matching distribution found for tensorflow==2.3.1.*
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Error: Error installing package(s): "\"tensorflow==2.3.1.*\"", "\"tensorflow-hub\"", "\"scipy\"", "\"requests\"", "\"pyyaml==3.12\"", "\"Pillow\"", "\"h5py==2.10.0\"", "\"pandas\"

skorch

Should really look at skorch.readthedocs.io. I think this has many things we might want!

Check for presence of `num_layers` when `stacked` is `TRUE`

When you set stacked to TRUE but don't have num_layers given in the ParamSet then the error that comes is not very informative:

Error in py_call_impl(callable, dots$args, dots$keywords) :
  TypeError: ('Keyword argument not understood:', 'NA')

kerasff - Evaluation error: missing value where TRUE/FALSE needed.

The following minimal example leads to an error:

iris_task <- tsk("iris")  
lrn_keras_ff <- lrn("classif.kerasff")
lrn_keras_ff$train(iris_task)

The error is:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
  RuntimeError: Evaluation error: missing value where TRUE/FALSE needed.

Detailed traceback: 
  File "/Users/Jacky/.virtualenvs/r-reticulate/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 728, in fit
    use_multiprocessing=use_multiprocessing)
  File "/Users/Jacky/.virtualenvs/r-reticulate/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 372, in fit
    prefix='val_')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 88, in __exit__
    next(self.gen)
  File "/Users/Jacky/.virtualenvs/r-reticulate/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 685, in on_epoch
    self.callbacks.on_epoch_end(epoch, epoch_logs)
  File "/Users/Jacky/.virtualenvs/r-reticulate/lib/python3.6/site-packages/tensorflow_core/python/keras/callbacks.py", line 298, in on_epoch_end
    callback.on_epoch_end(epoch, logs)
  File "/Library/Frameworks/R.fra

The tests currently include the line:

po_lrn$param_set$values$layer_units = integer()

This suppresses the error, consequently tests pass, but it looks like something doesn't work. I'm not sure what's causing this.

tabnet - ValueError: Number of groups (2) must be a multiple of the number of channels (13).

Minimal example:

wine_task <- tsk("wine")
lrn_tabnet <- lrn("classif.tabnet")
lrn_tabnet$train(wine_task)
ValueError: Number of groups (2) must be a multiple of the number of channels (13).

This is due to tf-tabnet implementing group normalisation with a default of num_groups = 2, and the input dimension not being even and for this dataset it would be a prime number.

Due to mlr3keras doing the work to one hot features behind the scenes, it's not immediately obvious whether the input dimension will be odd or even.

Consequently I would argue we should set it to default at 1L rather than 2L so that the learner will train with default settings even though the upstream package defaults at 2, or to use batch_norm as per the original TabNet paper.

Feature request: Tabnet

Tabnet model by Google researchers (https://arxiv.org/abs/1908.07442) claims the model architecture "outperforms other neural network and decision tree variants on a wide range of tabular data learning datasets and yields interpretable feature attributions and insights into the global model behavior. "

There is a Python package for keras/tensorflow 2.0 (tabnet) and one for Pytorch (pytorch-tabnet).

Here is a short R POC of the iris example from the former:

library("reticulate")
library("tensorflow")
library("keras")
# keras::install_keras(extra_packages = c("tensorflow-hub", "tabnet==0.1.3"))

use_implementation("tensorflow")

tabnet <- import("tabnet") #0.1.3 could not get 0.1.4 to work filed issue

col_names = c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width')

feature_columns <- lapply(col_names, function(x) { tf$feature_column$numeric_column(x)})

# Group Norm does better for small datasets
# n.b. name of class changes in 0.1.4 (that I could not get to work)
model = tabnet$TabNetClassification(feature_columns, num_classes=3,
                                    feature_dim=4, output_dim=4,
                                    num_decision_steps=2, relaxation_factor=1.0,
                                    sparsity_coefficient=1e-5, batch_momentum=0.98,
                                    virtual_batch_size=NULL, norm_type='group',
                                    num_groups=1)
model %>% compile(
  loss='categorical_crossentropy',
  optimizer = optimizer_adam(),
  metrics=c('accuracy')
)

iris["Sepal.Length"]

x <- lapply(col_names, function(x) { as.matrix(iris[x])})
names(x) <- col_names

y <- model.matrix(~ 0 + iris$Species)

model %>%
  fit(x, y, epochs=100, verbose=2)

The `imagepathdf_from_imagenet_dir` function

'mlr3keras.Rmd'

`library(mlr3)
library(mlr3misc)
library(data.table)
library(mlr3keras)

dir = "C:/Users/User/Documents/temp_data/imagenette2-160/train"
dt = imagepathdf_from_imagenet_dir(dir)`

Error in imagepathdf_from_imagenet_dir (dir):
can't find function "imagepathdf_from_imagenet_dir"

Doesn't this function exist?

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=Russian_Russia.1251 LC_CTYPE=Russian_Russia.1251
[3] LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C
[5] LC_TIME=Russian_Russia.1251

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] mlr3keras_0.1.3 data.table_1.13.7 mlr3misc_0.7.0 mlr3_0.10.0-9000

loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 rstudioapi_0.13 whisker_0.4
[4] knitr_1.31 magrittr_2.0.1 uuid_0.1-4
[7] lattice_0.20-41 R6_2.5.0 rlang_0.4.10
[10] lgr_0.4.2 tools_4.0.3 grid_4.0.3
[13] checkmate_2.0.0 xfun_0.21 tfruns_1.4
[16] htmltools_0.5.1.1 keras_2.3.0.0.9000 yaml_2.2.1
[19] digest_0.6.27 crayon_1.4.1 tensorflow_2.2.0.9000
[22] Matrix_1.2-18 paradox_0.7.0-9000 base64enc_0.1-3
[25] zeallot_0.1.0 evaluate_0.14 rmarkdown_2.6
[28] compiler_4.0.3 generics_0.1.0 backports_1.2.1
[31] jsonlite_1.7.2 reticulate_1.18

bug with benchmarking keras model?

Hi,

I played around with the vignette

library("mlr3tuning")
learner = lrn("regr.keras", callbacks = list(cb_es(patience = 3)))
task = mlr_tasks$get("mtcars")
resampling = rsmp("holdout")
measure = msr("regr.mse")
tuner = tnr("grid_search", resolution = 2)
terminator = trm("evals", n_evals = 4)
instance = TuningInstanceSingleCrit$new(
  task = task,
  learner = learner,
  resampling = resampling,
  measure = measure,
  search_space = ps,
  terminator = terminator
)
tuner$optimize(instance)

I get the following error

INFO  [15:42:57.254] Starting to optimize 2 parameter(s) with '<OptimizerGridSearch>' and '<TerminatorEvals>' 
INFO  [15:42:57.367] Evaluating 1 configuration(s) 
INFO  [15:42:57.427] Benchmark with 1 resampling iterations 
INFO  [15:42:57.433] Applying learner 'regr.keras' on task 'mtcars' (iter 1/1) 
INFO  [15:43:00.008] Finished benchmark 
Error in as.vector(x, "list") : 
  cannot coerce type 'closure' to vector of type 'list'

here is my traceback

> traceback()
36: as.list.default(X)
35: as.list(X)
34: lapply(x, runlock, current_depth = current_depth + 1L)
33: FUN(X[[i]], ...)
32: lapply(x, runlock, current_depth = current_depth + 1L)
31: FUN(X[[i]], ...)
30: lapply(x, runlock, current_depth = current_depth + 1L)
29: FUN(X[[i]], ...)
28: lapply(x, runlock, current_depth = current_depth + 1L)
27: runlock(ans)
26: `[.data.table`(fact, , list(learner_param_vals = list(.SD$learner[[1L]]$param_set$values)), 
        keyby = "learner_hash")
25: fact[, list(learner_param_vals = list(.SD$learner[[1L]]$param_set$values)), 
        keyby = "learner_hash"]
24: .__ResultData__initialize(self = self, private = private, super = super, 
        data = data)
23: .subset2(public_bind_env, "initialize")(...)
22: ResultData$new(data)
21: .__BenchmarkResult__initialize(self = self, private = private, 
        super = super, data = data)
20: .subset2(public_bind_env, "initialize")(...)
19: BenchmarkResult$new(grid)
18: benchmark(design, store_models = self$store_models)
17: .__ObjectiveTuning__.eval_many(self = self, private = private, 
        super = super, xss = xss)
16: private$.eval_many(xss)
15: .__Objective__eval_many(self = self, private = private, super = super, 
        xss = xss)
14: self$objective$eval_many(xss_trafoed)
13: .__OptimInstance__eval_batch(self = self, private = private, 
        super = super, xdt = xdt)
12: inst$eval_batch(g$data[inds])
11: .__OptimizerGridSearch__.optimize(self = self, private = private, 
        super = super, inst = inst)
10: private$.optimize(inst)
9: doTryCatch(return(expr), name, parentenv, handler)
8: tryCatchOne(expr, names, parentenv, handlers[[1L]])
7: tryCatchList(expr, classes, parentenv, handlers)
6: tryCatch({
       private$.optimize(inst)
   }, terminated_error = function(cond) {
   })
5: optimize_default(inst, self, private)
4: .__Optimizer__optimize(self = self, private = private, super = super, 
       inst = inst)
3: private$.optimizer$optimize(inst)
2: .__TunerFromOptimizer__optimize(self = self, private = private, 
       super = super, inst = inst)
1: tuner$optimize(instance)

and my session info

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin19.5.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /usr/local/Cellar/openblas/0.3.10_1/lib/libopenblasp-r0.3.10.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] paradox_0.4.0-9000    mlr3tuning_0.4.0.9000 mlr3keras_0.1.2       mlr3pipelines_0.2.1   mlr3_0.7.0-9000      
 [6] forcats_0.5.0         stringr_1.4.0         dplyr_1.0.1           purrr_0.3.4           readr_1.3.1          
[11] tidyr_1.1.1           tibble_3.0.3          ggplot2_3.3.2         tidyverse_1.3.0       keras_2.3.0.0        
[16] drake_7.12.6         

loaded via a namespace (and not attached):
 [1] colorspace_1.4-1   ellipsis_0.3.1     rprojroot_1.3-2    base64enc_0.1-3    fs_1.4.2          
 [6] rstudioapi_0.11    listenv_0.8.0      remotes_2.1.1      fansi_0.4.1        lubridate_1.7.9   
[11] xml2_1.3.2         codetools_0.2-16   knitr_1.29         pkgload_1.1.0      zeallot_0.1.0     
[16] jsonlite_1.7.1     broom_0.7.0        dbplyr_1.4.4       tfruns_1.4         compiler_4.0.2    
[21] httr_1.4.1         backports_1.1.10   assertthat_0.2.1   Matrix_1.2-18      cli_2.0.2         
[26] htmltools_0.5.0    prettyunits_1.1.1  tools_4.0.2        igraph_1.2.5       gtable_0.3.0      
[31] glue_1.4.2         Rcpp_1.0.5         cellranger_1.1.0   vctrs_0.3.4        xfun_0.15         
[36] globals_0.13.1     ps_1.4.0           mlr3measures_0.3.0 testthat_2.3.2     rvest_0.3.5       
[41] lifecycle_0.2.0    renv_0.11.0        devtools_2.3.0     future_1.19.1      scales_1.1.1      
[46] lgr_0.3.4          mlr3filters_0.3.0  hms_0.5.3          parallel_4.0.2     yaml_2.2.1        
[51] curl_4.3           memoise_1.1.0      reticulate_1.16    stringi_1.4.6      tensorflow_2.2.0  
[56] desc_1.2.0         checkmate_2.0.0    filelock_1.0.2     pkgbuild_1.0.8     storr_1.2.1       
[61] rlang_0.4.8        pkgconfig_2.0.3    evaluate_0.14      lattice_0.20-41    processx_3.4.4    
[66] tidyselect_1.1.0   here_0.1           magrittr_1.5       R6_2.4.1           generics_0.0.2    
[71] base64url_1.4      txtq_0.2.3         DBI_1.1.0          pillar_1.4.6       haven_2.3.1       
[76] whisker_0.4        withr_2.2.0        future.apply_1.6.0 modelr_0.1.8       crayon_1.3.4      
[81] uuid_0.1-4         utf8_1.1.4         rmarkdown_2.3      progress_1.2.2     usethis_1.6.1     
[86] grid_4.0.2         readxl_1.3.1       data.table_1.13.0  blob_1.2.1         callr_3.4.3       
[91] mlr3misc_0.6.0     bbotk_0.2.2        reprex_0.3.0       digest_0.6.25      munsell_0.5.0     
[96] sessioninfo_1.1.1 

Restore weights to continue training

Perhaps also should be able to set a hyperparameter "weights" that allows me to set the weights.
This could then be used for checkpointing and transfer learning etc.

Feature request: Regression

Currently there is only classification. It would be nice to have the equivalent of LearnerClassifKeras for Regr.

A cool feature to have would be a y_range for regression of non-negative (apply exponential at the last layer) or range-bound (apply sigmoid transform) similar to how the fast.ai tabular does it.

Would be interested to help.

Error: Input has undefined `axis` dimension

Hi folks, any idea why this could be happening?

Error in py_call_impl(callable, call_args$unnamed, call_args$named) :
ValueError: ('Input has undefined axis dimension. Input shape: ', TensorShape([None, 54]))

The dataset is formed by a target variable (column 1) and 50+ attributes on the following columns.

Save models

Test and check that models can be safely serialized.
Export / Offer a "save" function.

mlr3keras Installation Error

I am trying to install mlr3keras on R v. 4.0.2 and get the following error:

 remotes::install_github('mlr-org/mlr3keras')

Downloading GitHub repo mlr-org/mlr3keras@master

Error: Failed to install 'mlr3keras' from GitHub:
  Missing commas separating Remotes: 'mlr-org/bbotk
    mlr-org/mlr3'

Please advise. Thank you!

Feature request: Fit via generator

For modelling out of core datasets exceeding memory size, it seems like mlr3db provides a suitable backend, and keras should in theory be a good model for online learning.

Reading the source code, it looks like the dataset is read into memory and so I would run out.

It should be possible to read it chunk by chunk and trained using keras::fit_generator. Can help if needed.

review

Application of mlr3keras from a user perspective. Work in progress.

  • README.md - Links to learners do not work.
  • README.md - reticulate::conda_create() is called with python=3.8 but keras::install_keras() switches to python version 3.7
  • Why does LearnerClassifKerasFF$new() starts installing keras and tensorflow again?

Installation that works for me:

reticulate::install_miniconda()

reticulate::conda_create(
  envname = "mlr3keras",
  packages = c("pandas", "python=3.7")
)

Sys.setenv(RETICULATE_PYTHON = "/home/marc/.local/share/r-miniconda/envs/mlr3keras/bin/python")
keras::install_keras("conda", tensorflow="2.3.1", envname="mlr3keras")
reticulate::use_condaenv("mlr3keras")
  • If reticulate is not forced to use /home/marc/.local/share/r-miniconda/envs/mlr3keras/bin/python, it uses /home/marc/.local/share/r-miniconda/envs/r-reticulate/bin/python with python 3.6. Calling reticulate::use_condaenv("mlr3keras") does not change this behavior.
  • README.md - Do not use lrn as a variable name

"classif.kerascnn" Feature Types Errors

Description

Hi, I was confused with when using "classif.kerascnn" method the "Feature Types" is "-". And the error is not supporting numeric feature type when training the learner.

The following is a demonstration:

Reproducible example

> lrn = lrn("classif.kerascnn")
> lrn
<LearnerClassifKeras:classif.keras>
* Model: -
* Parameters: epochs=100, callbacks=<list>, validation_split=0.3333,
  batch_size=128, low_memory=FALSE, verbose=0, application=<function>,
  optimizer=<keras.optimizer_v2.adam.Adam>, loss=categorical_crossentropy,
  metrics=accuracy, cl_layer_units=1024, output_activation=softmax,
  unfreeze_n_last_layers=5, validation_fraction=0.2
* Packages: mlr3, keras
* Predict Types:  [response], prob
* Feature Types: -
* Properties: multiclass, twoclass
>lrn$train(tsk("iris"))
Error: <TaskClassif:iris> has the following unsupported feature types: numeric

use sgdr scheduler tf impl

callback_learning_rate_scheduler(tf$keras$experimental$CosineDecayRestarts(0.001, 100, t_mul = 2, m_mul = .8))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.