From Dataset Node
Overview
The From Dataset node reads images from a dataset of the Rosepetal platform, through a firebase-config node, and puts them in a message as raw pixels, ready for the inference nodes. It works in one of three retrieval modes:
| Retrieval mode | Each input message | Use it to |
|---|---|---|
| Fetch on demand (default) | Downloads one random image that matches the filters and adds it to the message | Test a flow with fresh images from a large dataset |
| Pre-download images | Adds one random image from a pool downloaded when the node starts | Send images fast and often, from a small fixed set |
| Stream entire dataset | Is a command (start, pause, stop); after start the node sends every matching image, one per interval | Run a model over a whole dataset |
Key Features
- Tag and set filters: one tag, or all; one set (Train, Validation, Test, Predetermined), or all
- Message overrides: in Fetch on demand and Stream entire dataset modes the dataset, tag and set can come from
msg, flow or global context - Buffered streaming: images are downloaded ahead of time, as many as the measured download time and the interval require
- Raw output: pixels as a
Bufferwith width, height, channels and color space (RGB or BGR) - Survives disconnections: messages that arrive while Firebase reconnects are queued and processed afterwards
Configuration
| Property | Default | Meaning |
|---|---|---|
| Name | from-dataset | Label of the node |
| Firebase configuration | none (required) | The firebase-config node of the project. The other fields are enabled once it is connected |
| Retrieval mode | Fetch on demand | Fetch on demand, Pre-download images or Stream entire dataset |
| Use msg properties | off | Fetch on demand and Stream entire dataset only. Reads the dataset, tag and set from the fields below instead of the dropdowns |
| Dataset | none | Dataset to read. The dropdown lists the datasets of the project and stores the dataset id |
| Tag | All tags | Only images of this tag. The dropdown shows the number of images of each tag |
| Set | All sets | All sets, Train, Validation, Test or Predetermined |
| Filtered count | - | Read only. Number of images that match the selected tag and set |
| Interval (ms) | 1000 | Stream entire dataset only. Time between two images: a number, or a msg, flow or global property that holds one. Values below 100 are raised to 100 |
| Dataset field / Tag field / Set field | empty | With Use msg properties. msg, flow or global property that holds the dataset (id or name), the tag id and the set (for example TRAIN). The dataset field is required; an empty tag or set field means all tags or all sets |
| Number of cached images | 10 | Pre-download images only. Size of the pool, from 1 to 50 |
| BGR | off | Swaps the red and blue channels: the image comes out as BGR or BGRA instead of RGB or RGBA |
| Output field | image | msg property that receives the image |
Retrieval Modes
Fetch on demand
Every input message gets one image, chosen at random among the images that match the dataset, tag and set. To keep reads low, the node draws from a pool of matching images that it reads from Firestore 200 at a time and keeps for 5 minutes, or until a dataset changes. The message is passed on with the image in the Output field.
With Use msg properties, each message says which dataset, tag and set to use:
// Dataset field: msg.payload.dataset, Tag field: msg.payload.tag, Set field: msg.payload.set
msg.payload = { dataset: "rp-class-bottle_caps", tag: "SCRATCH", set: "TRAIN" };
return msg;Pre-download images
When the node starts it downloads Number of cached images random images that match the dataset, tag and set, and keeps them in a folder of the system's temporary directory (node-red-rosepetal-vp-cache/from-dataset/<node id>). Every input message gets one image picked at random from that pool, with no download. The pool is reused after a restart or a redeploy as long as the dataset, tag, set and number do not change; it is deleted when the node is deleted. Message overrides are not available in this mode.
Stream entire dataset
The node sends every image that matches the dataset, tag and set, newest first, one every Interval (ms). The input messages are commands, in msg.payload:
msg.payload | Command |
|---|---|
"start", true, { "command": "start" }, or no payload | Start, or resume after a pause |
"pause", { "command": "pause" } | Pause and remember the position |
"stop", false, { "command": "stop" } | Stop and go back to the first image |
Any other payload is rejected with the warning Unsupported payload for all dataset mode command. An inject node with its default timestamp payload is rejected: set its payload to the string start or to true.
startafter apauseresumes where it stopped if the dataset, tag and set are the same; otherwise, and when a stream is running, it starts again from the first image.- The interval and, with Use msg properties, the dataset, tag and set are read from the
startmessage. - Before the first image the node downloads one image to measure the download time, then fills a buffer of
ceil(download time / (interval × 0.2))images, at least 2 and at most 50, waiting at most 30 seconds. - An image that cannot be downloaded is retried twice, after 1 and 2 seconds. An image that cannot be decoded is skipped with the error
Error processing image <index>: <reason>. - After the last image the status shows
Complete: N/Nand the nextstartbegins again from the first image.
Output
The image is written to the Output field (msg.image by default):
{
data: Buffer, // pixels, row by row, channels interleaved
width: 1920,
height: 1080,
channels: 3, // 1, 3 or 4
colorSpace: "RGB", // "GRAY", "RGB", "RGBA", "BGR" or "BGRA"
dtype: "uint8",
name: "1759745408220_cam1_a" // name of the image in the dataset
}Grayscale images keep one channel (GRAY); images with alpha keep four. BMP files that the image library cannot read are decoded by the node itself (24 and 32 bits, uncompressed).
In Fetch on demand and Pre-download images modes the rest of the input message is passed on unchanged. In Stream entire dataset mode every image is sent in a copy of the start message, with these properties added:
| Property | Meaning |
|---|---|
imageIndex | Position of the image in the stream, from 1 |
totalImages | Number of images that match the filters |
dataset | Name of the dataset |
tag | Tag filter, ALL_TAGS when none |
set | Set filter, ALL_SETS when none |
Fetch Limit and Disconnections
Every image downloaded counts toward the fetch limit of the firebase-config node (5000 a day). The images of a pool count when the pool is downloaded, not when they are sent.
- Fetch on demand: while the limit is reached, input messages are dropped and the status shows
Fetch limit reached — reset firebase-config. - Stream entire dataset:
startfails withFirebase fetch limit reached. Reset in firebase-config node., and a running stream stops with the statusFetch limit reached — stream stopped. After Restart limit, sendstartagain. - Pre-download images: after Restart limit, a pool that could not be downloaded is downloaded again by itself.
When the Firebase connection is lost, a running stream is paused, and up to 50 input messages are queued (more are dropped with a warning). They are processed in order when the connection returns. A paused stream is not resumed by itself: send start.
Node Status
| Status | Meaning |
|---|---|
Loading dataset | Starting |
green Ready (fetch on demand: <dataset>), Ready (fetch: msg props required) | Fetch on demand mode is ready |
green Dataset loaded (cached) | The pool is ready |
green Ready (stream: <dataset>), Ready (stream: msg props required) | Stream mode is ready for a start |
blue Measuring download speed..., Initializing buffer..., Loading buffer: n/m | Preparing a stream |
blue Streaming: i/N (buf: b, dl: d) | Sending image i of N, b images buffered, d downloading |
yellow Waiting: i/N (buf: b, dl: d) | The next image is still downloading |
yellow Paused at i/N, blue Resuming at i/N | Paused, resumed |
green Complete: N/N (avg: X ms) | The stream ended; average download time |
grey Stopped | Stopped by a stop command |
yellow No images match filters | Nothing to stream |
yellow ring Firebase disconnected - queuing messages, Disconnected - queued N msg(s), Reconnecting - queued N msg(s) | Waiting for the Firebase connection |
green Reconnected - processing queued messages | Connection back |
red Firebase config not set, Firebase config not ready | No firebase-config, or it could not connect |
red Dataset not found, Dataset not configured, Dataset required (msg or config) | The dataset is missing or does not exist in the project |
red No images found in dataset / tag / set selected | The pool could not be filled |
Errors
| Error | Cause |
|---|---|
<name> not ready | A message arrived before the node finished starting, or after it failed to start |
Dataset not found: <dataset> | The dataset of the configuration or of the message is not in the project |
Dataset field is required when using message properties | Use msg properties is on and the message has no dataset |
No images found in dataset / tag / set selected | No image matches the filters |
No cached images available | Pre-download mode without a pool |
Predownload failed: <reason> | The pool could not be downloaded |
Error processing image: <reason> | The download or the decoding failed |
Examples
Run a model on random images
[inject every 2 s] → [from-dataset: Fetch on demand, Tag OK] → [inferencer] → [debug]Set the inferencer to read its image from msg.image, the default Output field of from-dataset.
Run a model over a whole dataset
[inject: payload "start"] ─┐
[inject: payload "pause"] ─┼→ [from-dataset: Stream entire dataset, Interval 500] → [inferencer] → [function]
[inject: payload "stop"] ─┘The function node can record each result with the index of its image:
flow.set(`result_${msg.imageIndex}`, msg.payload);
node.status({ text: `${msg.imageIndex}/${msg.totalImages}` });
return null;See Also
- Firebase Config Node - The connection and its fetch limit
- List Dataset Node - Ids, tags and image counts of the datasets
- Inferencer Node - Run a model on the images
- Dataset Upload Node - Upload images to a dataset