Problem & suggested fix in beginner tutorials - Loading Image Data

Open
#525 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
55/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
r, tensorflow

Research direction

Start with the linked “Load using tf.data” tutorial and inspect the get_label function and its tf$strings$split call. Reproduce the labeled_ds error, verify the path separator correction, and confirm that the tutorial runs without the slice-index failure.

Written by the indexing model from the issue text.

Description

Hi Team,

TLDR:
Please check the change in instruction from "/" to "\\" :

get_label <- function(file_path) {
        parts <- tf$strings$split(file_path, "/")
        parts[-2] %>% 
                tf$equal(classes) %>% 
                tf$cast(dtype = tf$float32)
}

Longer:
I was recently going through the loading image dataset tutorial, and got the following error when applying the below code:

Code:

# num_parallel_calls are going to be autotuned
labeled_ds <- list_ds %>%  dataset_map(preprocess_path, num_parallel_calls = tf$data$experimental$AUTOTUNE)

Error:

2022-04-09 12:16:47.207451: W tensorflow/core/framework/op_kernel.cc:1745] OP_REQUIRES failed at strided_slice_op.cc:108 : INVALID_ARGUMENT: slice index -1 of dimension 0 out of bounds.
Error in py_iter_next(it, completed) : 
  InvalidArgumentError: {{function_node __wrapped__IteratorGetNext_output_types_2_device_/job:localhost/replica:0/task:0/device:CPU:0}} slice index -1 of dimension 0 out of bounds.
	 [[{{node strided_slice}}]] [Op:IteratorGetNext]

After a bit of tinkering, I found that the get_label function was not splitting the directory path correctly. This resulted in the data_map function not being able to function correctly. This was because the file path containing the category was not being plit through tf$strings$split (split) and hence couldn't be compared through tf$equal(classes). Thus, the sep value of / was causing the error. Please see the TLDR section for the suggested fix.

Dominant language
R
Stars
1.3k
Forks
316
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rstudio/tensorflow

All issues in rstudio/tensorflow

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.