Problem on Benchmark Code

I was skimming through the benchmark notebook you introduced in your blog.

def add_paths(df, feature_dir, label_dir=None, bands=BANDS):
    """
    Given dataframe with a column for chip_id, returns a dataframe with a column
    added indicating the path to each band's TIF image as "{band}_path", eg "B02_path".
    A column is also added to the dataframe with paths to the label TIF, if the
    path to the labels directory is provided.
    """
    for band in bands:
        df[f"{band}_path"] = feature_dir / df["chip_id"] / f"{band}.tif"
        assert df[f"{band}_path"].path.exists().all()
    if label_dir is not None:
        df["label_path"] = label_dir / (df["chip_id"] + ".tif")
        assert df["label_path"].path.exists().all()

    return df


train_meta = add_paths(train_meta, TRAIN_FEATURES, TRAIN_LABELS)
train_meta.head()

The above code cell is throwing an error:
TypeError: expected str, bytes or os.PathLike object, not Series

Hope you will fix it.

1 Like

This can be a probable solution -

def add_paths(df, feature_dir, label_dir=None, bands=BANDS):
  for band in bands:
      band_paths = []
      for chip_id in df.chip_id:
          current_path = feature_dir / chip_id / f"{band}.tif"
          band_paths.append(current_path)
          assert current_path.is_file()
      df[f"{band}_path"] = band_paths
  if label_dir is not None:
      label_paths = []
      for chip_id in df.chip_id:
          current_path = label_dir / (chip_id + ".tif")
          assert current_path.is_file()
      df["label_path"] = label_paths
  return df

train_meta = add_paths(train_meta, TRAIN_FEATURES, TRAIN_LABELS)
train_meta.head()
1 Like

@Tashin That error is not raised when we run the benchmark - we are able to run it from end to end with no issues.

If you provide more detail on your error (eg. the stack trace, what you are using as arguments) others may be able to help debug. One thought is to check the competition runtime environment specifications and see if you have any mismatching package versions.

You could also run the notebook the Planetary Computer Hub instead - it is available in their tutorials here.

Good luck!

1 Like