andrewzm / deepIDE

Deep IDE Models for Spatio-Temporal Forecasting
21 stars 9 forks source link

Error in py_call_impl(callable, dots$args, dots$keywords) : #3

Open 19211020075 opened 3 years ago

19211020075 commented 3 years ago

Hi, Andrewzm. When I "run validation...", the following code: `## For each epoch for(epoch in 1:nepochs) {

Do all validation cases

cat("Running validation... \n") N_Val_Batches <- floor(length(idxVal)/32L) # about 237 , 验证 Val_Batch_idx <- rep(1:N_Val_Batches, each = 32L) # batch ID if((partbatch <- length(idxVal) %% 32L) > 0) { # if not an exact multiple of 32 N_Val_Batches <- N_Val_Batches + 1 # then there is an extra batch Val_Batch_idx <- c(Val_Batch_idx, rep(N_Val_Batches, partbatch)) }

Create an idx--batch map

val_batches <- data.frame(idx = idxVal, batch = Val_Batch_idx)

For each batch compute the NLL

ValCosts <- lapply(unique(val_batches$batch), function(i) { idx_val <- filter(val_batches, batch == i)$idx fd <- dict(data_in = d[idx_val,,,], data_current = dfinal[idx_val,,,drop=F], data_future = dpred[idx_val,,,drop=F]) run(Cost1, feed_dict = fd) })

Compute summary statistics at this epoch

Epoch_val[epoch, ] <- c(mean(unlist(ValCosts)), median(unlist(ValCosts)), sd(unlist(ValCosts)), mad(unlist(ValCosts)))

Initialise

epoch_order <- idxTrain count <- 0 Objective[[epoch]] <- Objective_val[[epoch]] <- rep(0, nsteps_per_epoch)

while(length(epoch_order) >= N_Batch) {

train_cov_pars <- (epoch >= (28L))       # Estimate cov. pars if epoch >= 28
count <- count + 1                       # increment batch number in epoch
idx <- epoch_order[1:N_Batch]            # Take first N_Batch
epoch_order <- epoch_order[-(1:N_Batch)] # Remove first batch from list
fd <- dict(data_in = d[idx,,,],          # Creat dictionary
           data_current = dfinal[idx,,,drop=F],
           data_future = dpred[idx,,,drop=F])

if(train_cov_pars) {
  TFrun <- run(list(trainnetcov, Cost1), feed_dict = fd)
} else {
  TFrun <- run(list(trainnet, Cost1), feed_dict = fd) # Train network on its own  
}

## Get Cost for this batch
Objective[[epoch]][count] <- TFrun[[2]]

## Every 10 samples do a random validation check
if((count %% 10) == 0) {
  idx_val <- sample(idxVal, N_Batch, replace = FALSE)
  fd <- dict(data_in = d[idx_val,,,],
             data_current = dfinal[idx_val,,,drop=F],
             data_future = dpred[idx_val,,,drop=F])
  Objective_val[[epoch]][count/10] <- run(Cost1, feed_dict = fd)
  cat(paste0("Epoch ", epoch, " ...  Step ", count, 
             " ... Cost: ", Objective_val[[epoch]][count/10], "\n"))
}

Epoch_train[epoch, ] <- c(mean(Objective[[epoch]]),
                          median(Objective[[epoch]]),
                          sd(Objective[[epoch]]),
                          mad(Objective[[epoch]]))

} } `
There's an error: Error in py_call_impl(callable, dots$args, dots$keywords) : ValueError: Dimensions must be equal, but are 64 and 3 for 'Less_2' (op: 'Less') with input shapes: [?,64,64], [?,64,64,3].

Could you please help me? Thanks.

andrewzm commented 3 years ago

Hi, can you please confirm the original code worked without error before you changed dates and data sizes?

On Sat, 10 Apr 2021, 12:22 19211020075, @.***> wrote:

Hi, Andrewzm. When I "run validation...", the following code: `## For each epoch for(epoch in 1:nepochs) { Do all validation cases

cat("Running validation... \n") N_Val_Batches <- floor(length(idxVal)/32L) # about 237 , 验证 Val_Batch_idx <- rep(1:N_Val_Batches, each = 32L) # batch ID if((partbatch <- length(idxVal) %% 32L) > 0) { # if not an exact multiple of 32 N_Val_Batches <- N_Val_Batches + 1 # then there is an extra batch Val_Batch_idx <- c(Val_Batch_idx, rep(N_Val_Batches, partbatch)) } Create an idx--batch map

val_batches <- data.frame(idx = idxVal, batch = Val_Batch_idx) For each batch compute the NLL

ValCosts <- lapply(unique(val_batches$batch), function(i) { idx_val <- filter(val_batches, batch == i)$idx fd <- dict(data_in = d[idx_val,,,], data_current = dfinal[idx_val,,,drop=F], data_future = dpred[idx_val,,,drop=F]) run(Cost1, feed_dict = fd) }) Compute summary statistics at this epoch

Epoch_val[epoch, ] <- c(mean(unlist(ValCosts)), median(unlist(ValCosts)), sd(unlist(ValCosts)), mad(unlist(ValCosts))) Initialise

epoch_order <- idxTrain count <- 0 Objective[[epoch]] <- Objective_val[[epoch]] <- rep(0, nsteps_per_epoch)

while(length(epoch_order) >= N_Batch) {

train_cov_pars <- (epoch >= (28L)) # Estimate cov. pars if epoch >= 28

count <- count + 1 # increment batch number in epoch

idx <- epoch_order[1:N_Batch] # Take first N_Batch

epoch_order <- epoch_order[-(1:N_Batch)] # Remove first batch from list

fd <- dict(data_in = d[idx,,,], # Creat dictionary

       data_current = dfinal[idx,,,drop=F],

       data_future = dpred[idx,,,drop=F])

if(train_cov_pars) {

TFrun <- run(list(trainnetcov, Cost1), feed_dict = fd)

} else {

TFrun <- run(list(trainnet, Cost1), feed_dict = fd) # Train network on its own

}

Get Cost for this batch

Objective[[epoch]][count] <- TFrun[[2]]

Every 10 samples do a random validation check

if((count %% 10) == 0) {

idx_val <- sample(idxVal, N_Batch, replace = FALSE)

fd <- dict(data_in = d[idx_val,,,],

         data_current = dfinal[idx_val,,,drop=F],

         data_future = dpred[idx_val,,,drop=F])

Objective_val[[epoch]][count/10] <- run(Cost1, feed_dict = fd)

cat(paste0("Epoch ", epoch, " ... Step ", count,

         " ... Cost: ", Objective_val[[epoch]][count/10], "\n"))

}

Epoch_train[epoch, ] <- c(mean(Objective[[epoch]]),

                      median(Objective[[epoch]]),

                      sd(Objective[[epoch]]),

                      mad(Objective[[epoch]]))

} } ` There's an error: Error in py_call_impl(callable, dots$args, dots$keywords) : ValueError: Dimensions must be equal, but are 64 and 3 for 'Less_2' (op: 'Less') with input shapes: [?,64,64], [?,64,64,3].

Could you please help me? Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/andrewzm/deepIDE/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABEU3KS5SW7E4KMSPDS7Q3TH6Y5ZANCNFSM42V7QT7Q .