GitHub issue #5685: Broken Image render on the hub website
State: closed | Created: 2023-03-29T15:25:30Z

### Describe the bug

Hi :wave: 

Not sure if this is the right place to ask, but I am trying to load a huge amount of datasets on the hub (:partying_face: ) but I am facing a little issue with the `image` type

![image](https://user-images.githubusercontent.com/15908060/228587875-427a37f1-3a31-4e17-8bbe-0f759003910d.png)

See this [dataset](https://huggingface.co/datasets/Francesco/cell-towers), basically for some reason the first image has numerical bytes inside, not sure if that is okay, but the image render feature **doesn't work**

So the dataset is stored in the following way

```python
    builder.download_and_prepare(output_dir=str(output_dir))

    ds = builder.as_dataset(split="train")
    # [NOTE] no idea how to push it from the builder folder
    ds.push_to_hub(repo_id=repo_id)
    builder.as_dataset(split="validation").push_to_hub(repo_id=repo_id)
    ds = builder.as_dataset(split="test")
    ds.push_to_hub(repo_id=repo_id)
   ```
   
   The build is this class
   
   ```python
       class COCOLikeDatasetBuilder(datasets.GeneratorBasedBuilder):

        VERSION = datasets.Version("1.0.0")

        def _info(self):
            features = datasets.Features(
                {
                    "image_id": datasets.Value("int64"),
                    "image": datasets.Image(),
                    "width": datasets.Value("int32"),
                    "height": datasets.Value("int32"),
                    "objects": datasets.Sequence(
                        {
                            "id": datasets.Value("int64"),
                            "area": datasets.Value("int64"),
                            "bbox": datasets.Sequence(
                                datasets.Value("float32"), length=4
                            ),
                            "category": datasets.ClassLabel(names=categories),
                        }
                    ),
                }
            )
            return datasets.DatasetInfo(
                description=description,
                features=features,
                homepage=homepage,
                license=license,
                citation=citation,
            )

        def _split_generators(self, dl_manager):
            archive = dl_manager.download(url)

            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={
                        "annotation_file_path": "train/_annotations.coco.json",
                        "files": dl_manager.iter_archive(archive),
                    },
                ),
                datasets.SplitGenerator(
                    name=datasets.Split.VALIDATION,
                    gen_kwargs={
                        "annotation_file_path": "test/_annotations.coco.json",
                        "files": dl_manager.iter_archive(archive),
                    },
                ),
                datasets.SplitGenerator(
                    name=datasets.Split.TEST,
                    gen_kwargs={
                        "annotation_file_path": "valid/_annotations.coco.json",
                        "files": dl_manager.iter_archive(archive),
                    },
                ),
            ]

        def _generate_examples(self, annotation_file_path, files):
            def process_annot(annot, category_id_to_category):
                return {
                    "id": annot["id"],
                    "area": annot["area"],
                    "bbox": annot["bbox"],
                    "category": category_id_to_category[annot["category_id"]],
                }

            image_id_to_image = {}
            idx = 0

            # This loop relies on the ordering of the files in the archive:
            # Annotation files come first, then the images.
            for path, f in files:
                file_name = os.path.basename(path)
                if annotation_file_path in path:
                    annotations = json.load(f)
                    category_id_to_category = {
                        category["id"]: category["name"]
                        for category in annotations["categories"]
                    }
                    print(category_id_to_category)
                    image_id_to_annotations = collections.defaultdict(list)
                    for annot in annotations["annotations"]:
                        image_id_to_annotations[annot["image_id"]].append(annot)
                    image_id_to_image = {
                        annot["file_name"]: annot for annot in annotations["images"]
                    }
                elif file_name in image_id_to_image:
                    image = image_id_to_image[file_name]
                    objects = [
                        process_annot(annot, category_id_to_category)
                        for annot in image_id_to_annotations[image["id"]]
                    ]
                    print(file_name)
                    yield idx, {
                        "image_id": image["id"],
                        "image": {"path": path, "bytes": f.read()},
                        "width": image["width"],
                        "height": image["height"],
                        "objects": objects,
                    }
                    idx += 1
```

Basically, I want to add to the hub every dataset I come across on coco format

Thanks 

Fra

### Steps to reproduce the bug

In this case, you can just navigate on the [dataset](https://huggingface.co/datasets/Francesco/cell-towers)

### Expected behavior

I was expecting the image rendering feature to work

### Environment info

Not a lot to share, I am using `datasets` from a fresh venv