Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with length of progress bar for validation loop #51

Closed
mattwarkentin opened this issue Jul 22, 2021 · 0 comments
Closed

Issue with length of progress bar for validation loop #51

mattwarkentin opened this issue Jul 22, 2021 · 0 comments

Comments

@mattwarkentin
Copy link
Contributor

mattwarkentin commented Jul 22, 2021

The length of the progress bars for both train and validation loops are only based on the number of batches for the training data loader.

I think there also needs to be a line break after the progress bar so that the metrics summary isn't on the same line.

Example:

library(luz)
library(torch)

ds <- 
  dataset(
    initialize = function(n) {
      self$x <- 
        torch_tensor(matrix(rnorm(n * 100), nrow = n))
      self$y <- 
        torch_tensor(matrix(sample(0:1, n, TRUE), nrow = n))$to(torch_float())
    },
    .length = function() {
      dim(self$x)[[1]]
    },
    .getitem = function(i) {
      list(
        self$x[i, ],
        self$y[i]
      )
    }
  )

train_dl <- dataloader(ds(1000), batch_size = 32, shuffle = TRUE)
test_dl <- dataloader(ds(500), batch_size = 32)

net <- nn_module(
  "Net",
  initialize = function() {
    self$fc1 = nn_linear(100, 10)
    self$out = nn_linear(10, 1)
  },
  forward = function(x) {
    x %>% 
      self$fc1() %>% 
      nnf_relu() %>% 
      self$out()
  }
)

fitted <- 
  net %>%
  setup(
    loss = nn_bce_with_logits_loss(),
    optimizer = optim_adam,
    metrics = list(
      luz_metric_binary_accuracy_with_logits()
    )
  ) %>%
  fit(
    data = train_dl, 
    epochs = 1, 
    valid_data = test_dl
  )
Epoch 1/1
16/32 [==========>-----------] - ETA:  1s - Loss: 0.7024  - Acc: 0.472 Train metrics: Loss: 0.6997 - Acc: 0.497
Valid metrics: Loss: 0.7024 - Acc: 0.472
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants