GithubHelp home page GithubHelp logo

Comments (1)

lartpang avatar lartpang commented on July 23, 2024

I have generate a croissant file by the following code:

import hashlib
import json

import mlcroissant as mlc
from etils import epath


# generate the sha256 string from a file
def get_sha256(path: str) -> str:
    with open(path, "rb") as f:
        context = f.read()
    return hashlib.sha256(context).hexdigest()


distribution = [
    mlc.FileObject(
        id="info-a",
        name="info-a",
        description="",
        content_url="path/info-a.json",
        encoding_format="application/json",
        sha256=get_sha256("info-a.json"),
    ),
    mlc.FileObject(
        id="info-b",
        name="info-b",
        description="",
        content_url="path/info-b.json",
        encoding_format="application/json",
        sha256=get_sha256("info-b.json"),
    ),
]

# The record set has the `image_id` and the `bbox` (short for bounding box).
record_sets = [
    mlc.RecordSet(
        id="record-a",
        name="record-a",
        fields=[
            mlc.Field(
                id="record-a/name",
                name="name",
                description="",
                data_types=mlc.DataType.TEXT,
                source=mlc.Source(
                    file_object="info-a",
                    extract=mlc.Extract(json_path="$[*].name"),
                ),
            ),
            mlc.Field(
                id="record-a/id",
                name="id",
                description="",
                data_types=mlc.DataType.INTEGER,
                source=mlc.Source(
                    file_object="info-a",
                    extract=mlc.Extract(json_path="$[*].id"),
                ),
            ),
        ],
    ),
    mlc.RecordSet(
        id="record-b",
        name="record-b",
        fields=[
            mlc.Field(
                id="record-b/unique_id",
                name="unique_id",
                description="",
                data_types=mlc.DataType.TEXT,
                source=mlc.Source(
                    file_object="info-b",
                    extract=mlc.Extract(json_path="$[*].unique_id"),
                ),
            ),
            mlc.Field(
                id="record-b/base_class",
                name="base_class",
                description="",
                data_types=mlc.DataType.TEXT,
                source=mlc.Source(
                    file_object="info-b",
                    extract=mlc.Extract(json_path="$[*].base_class"),
                ),
            ),
            mlc.Field(
                id="record-b/image",
                name="image",
                description="",
                data_types=mlc.DataType.TEXT,
                source=mlc.Source(
                    file_object="info-b",
                    extract=mlc.Extract(json_path="$[*].image"),
                ),
            ),
            mlc.Field(
                id="record-b/mask",
                name="mask",
                description="",
                data_types=mlc.DataType.TEXT,
                source=mlc.Source(
                    file_object="info-b",
                    extract=mlc.Extract(json_path="$[*].mask"),
                ),
            ),
        ],
    ),
]

metadata = mlc.Metadata(
    name="my-dataset",
    url="my-url",
    distribution=distribution,
    record_sets=record_sets,
)

jsonld = epath.Path("croissant.json")
with jsonld.open("w") as f:
    f.write(json.dumps(metadata.to_json(), indent=2))

from croissant.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.