fiftyone.core.session¶
Module contents¶
Session definitions for interacting with the FiftyOne App.
Functions:
Closes the FiftyOne App, if necessary. |
|
|
Launches the FiftyOne App. |
Classes:
|
Session that maintains a 1-1 shared state with the FiftyOne App. |
-
fiftyone.core.session.
close_app
() → None¶ Closes the FiftyOne App, if necessary.
If no App is currently open, this method has no effect.
-
fiftyone.core.session.
launch_app
(dataset: Optional[fiftyone.core.dataset.Dataset] = None, view: Optional[fiftyone.core.view.DatasetView] = None, sample_id: Optional[str] = None, group_id: Optional[str] = None, spaces: Optional[fiftyone.core.odm.workspace.Space] = None, color_scheme: Optional[fiftyone.core.odm.dataset.ColorScheme] = None, plots: Optional[fiftyone.core.plots.manager.PlotManager] = None, port: Optional[int] = None, address: Optional[str] = None, remote: bool = False, browser: Optional[str] = None, height: Optional[int] = None, auto: bool = True, config: Optional[fiftyone.core.config.AppConfig] = None) → fiftyone.core.session.session.Session¶ Launches the FiftyOne App.
Note that only one App instance can be opened at a time. If this method is called when another App exists, the existing App will be closed.
- Parameters
dataset (None) – an optional
fiftyone.core.dataset.Dataset
orfiftyone.core.view.DatasetView
to loadview (None) – an optional
fiftyone.core.view.DatasetView
to loadsample_id (None) – an optional
fiftyone.core.sample.Sample
ID to load in the modalgroup_id (None) – an optional
fiftyone.core.groups.Group
ID to load in the modalspaces (None) – an optional
fiftyone.core.odm.workspace.Space
instance defining a space configuration to loadcolor_scheme (None) – an optional
fiftyone.core.odm.dataset.ColorScheme
defining a custom color scheme to useplots (None) – an optional
fiftyone.core.plots.manager.PlotManager
to connect to this sessionport (None) – the port number to serve the App. If None,
fiftyone.config.default_app_port
is usedaddress (None) – the address to serve the App. If None,
fiftyone.config.default_app_address
is usedremote (False) – whether this is a remote session, and opening the App should not be attempted
browser (None) – an optional browser to use to open the App. If None, the default browser will be used. Refer to list of supported browsers at https://docs.python.org/3/library/webbrowser.html
height (None) – an optional height, in pixels, at which to render App instances in notebook cells. Only applicable in notebook contexts
auto (True) – whether to automatically show a new App window whenever the state of the session is updated. Only applicable in notebook contexts
config (None) – an optional
fiftyone.core.config.AppConfig
to control fine-grained default App settings
- Returns
a
Session
-
class
fiftyone.core.session.
Session
(dataset: Optional[Union[fiftyone.core.dataset.Dataset, fiftyone.core.view.DatasetView]] = None, view: Optional[fiftyone.core.view.DatasetView] = None, sample_id: Optional[str] = None, group_id: Optional[str] = None, spaces: Optional[fiftyone.core.odm.workspace.Space] = None, color_scheme: Optional[fiftyone.core.odm.dataset.ColorScheme] = None, plots: Optional[fiftyone.core.plots.manager.PlotManager] = None, port: Optional[int] = None, address: Optional[str] = None, remote: bool = False, browser: Optional[str] = None, height: Optional[int] = None, auto: bool = True, config: Optional[fiftyone.core.config.AppConfig] = None, view_name: Optional[str] = None)¶ Bases:
object
Session that maintains a 1-1 shared state with the FiftyOne App.
Basic Usage
Use
launch_app()
to launch the App and retrieve its correspondingSession
instance.To open a dataset in the App, simply set the
Session.dataset
property of the session to yourfiftyone.core.dataset.Dataset
.To load a specific view into your dataset, simply set the
Session.view
property of the session to yourfiftyone.core.view.DatasetView
.To load a specific sample in the modal, simply set the
Session.sample_id
property of the session to the ID of thefiftyone.core.sample.Sample
.To load a specific group in the modal, simply set the
Session.group_id
property of the session to the ID of thefiftyone.core.groups.Group
.To attach/remove interactive plots, use the methods exposed on the
Session.plots
property of the session.Use
Session.refresh()
to refresh the App if you update a dataset outside of the AppUse
Session.selected
to retrieve the IDs of the currently selected samples in the App.Use
Session.selected_labels
to retrieve the IDs of the currently selected labels in the App.In notebook contexts, use
Session.freeze()
to replace the App and any attached plots with static images.Use
Session.close()
andSession.open()
to temporarily close and reopen the App without creating a newSession
instance.Use
close_app()
to programmatically close the App and terminate the session.
- Parameters
dataset (None) – an optional
fiftyone.core.dataset.Dataset
orfiftyone.core.view.DatasetView
to loadview (None) – an optional
fiftyone.core.view.DatasetView
to loadsample_id (None) – an optional
fiftyone.core.sample.Sample
ID to load in the modalgroup_id (None) – an optional
fiftyone.core.groups.Group
ID to load in the modalspaces (None) – an optional
fiftyone.core.odm.workspace.Space
instance defining a space configuration to loadcolor_scheme (None) – an optional
fiftyone.core.odm.dataset.ColorScheme
defining a custom color scheme to useplots (None) – an optional
fiftyone.core.plots.manager.PlotManager
to connect to this sessionport (None) – the port number to serve the App. If None,
fiftyone.config.default_app_port
is usedaddress (None) – the address to serve the App. If None,
fiftyone.config.default_app_address
is usedremote (False) – whether this is a remote session, and opening the App should not be attempted
browser (None) – an optional browser to use to open the App. If None, the default browser will be used. Refer to list of supported browsers at https://docs.python.org/3/library/webbrowser.html
height (None) – an optional height, in pixels, at which to render App instances in notebook cells. Only applicable in notebook contexts
auto (True) – whether to automatically show a new App window whenever the state of the session is updated. Only applicable in notebook contexts
config (None) – an optional
fiftyone.core.config.AppConfig
to control fine-grained default App settings
Attributes:
The auto setting for the session.
The server port for the session.
The server address for the session, or None if not specified.
Whether the session is remote.
The URL of the session.
The current
fiftyone.core.config.AppConfig
.The current
fiftyone.core.groups.Group
ID in the modal, if any.The current
fiftyone.core.sample.Sample
ID in the modal, if any.The layout state for the session.
The color scheme for the session.
The
fiftyone.core.dataset.Dataset
connected to the session.The
fiftyone.core.view.DatasetView
connected to the session, orNone
if no view is connected.Whether this session has any attached plots.
The
fiftyone.core.plots.manager.PlotManager
instance that manages plots attached to this session.A list of sample IDs of the currently selected samples in the App, if any.
A list of labels currently selected in the App.
A
fiftyone.core.view.DatasetView
containing the currently selected content in the App.Methods:
load_workspace
(workspace)Loads the given saved workspace.
Clears the current
fiftyone.core.dataset.Dataset
from the session, if any.Clears the current
fiftyone.core.view.DatasetView
from the session, if any.refresh
()Refreshes the current App window.
Clears the currently selected samples, if any.
select_samples
([ids, tags])Selects the specified samples in the current view in the App,
select_labels
([labels, ids, tags, fields])Selects the specified labels in the current view in the App.
Clears the currently selected labels, if any.
tag_selected_samples
(tag)Adds the tag to the currently selected samples, if necessary.
Removes the tag from the currently selected samples, if necessary.
tag_selected_labels
(tag)Adds the tag to the currently selected labels, if necessary.
Removes the tag from the currently selected labels, if necessary.
summary
()Returns a string summary of the session.
open
()Opens the App, if necessary.
open_tab
()Opens the App in a new tab of your browser.
show
([height])Opens the App in the output of the current notebook cell.
no_show
()Returns a context manager that temporarily prevents new App instances from being opened in the current notebook cell when methods are run that normally would show new App windows.
wait
([wait])Blocks execution until the App is closed by the user.
close
()Closes the session and terminates the App, if necessary.
freeze
()Screenshots the active App cell, replacing it with a static image.
-
property
auto
¶ The auto setting for the session.
-
property
server_port
¶ The server port for the session.
-
property
server_address
¶ The server address for the session, or None if not specified.
-
property
remote
¶ Whether the session is remote.
-
property
url
¶ The URL of the session.
-
property
config
¶ The current
fiftyone.core.config.AppConfig
.For changes to a session’s config to take effect in the App, a call to
Session.refresh()
or another state-updating action such as session.view = my_view must occur.Example usage:
import fiftyone as fo dataset, session = fo.quickstart() # change the show confidence setting and push the change to the App session.config.show_confidence = False session.refresh()
-
property
group_id
¶ The current
fiftyone.core.groups.Group
ID in the modal, if any.
-
property
sample_id
¶ The current
fiftyone.core.sample.Sample
ID in the modal, if any.
-
property
spaces
¶ The layout state for the session.
-
load_workspace
(workspace: str) → None¶ Loads the given saved workspace.
- Parameters
workspace – the name of a saved workspace
-
property
color_scheme
¶ The color scheme for the session.
-
property
dataset
¶ The
fiftyone.core.dataset.Dataset
connected to the session.
-
clear_dataset
() → None¶ Clears the current
fiftyone.core.dataset.Dataset
from the session, if any.
-
property
view
¶ The
fiftyone.core.view.DatasetView
connected to the session, orNone
if no view is connected.
-
clear_view
() → None¶ Clears the current
fiftyone.core.view.DatasetView
from the session, if any.
-
property
has_plots
¶ Whether this session has any attached plots.
-
property
plots
¶ The
fiftyone.core.plots.manager.PlotManager
instance that manages plots attached to this session.
-
refresh
() → None¶ Refreshes the current App window.
-
property
selected
¶ A list of sample IDs of the currently selected samples in the App, if any.
-
clear_selected
() → None¶ Clears the currently selected samples, if any.
-
select_samples
(ids: Optional[Union[str, Iterable[str]]] = None, tags: Optional[Union[str, Iterable[str]]] = None) → None¶ Selects the specified samples in the current view in the App,
- Parameters
ids (None) – an ID or iterable of IDs of samples to select
tags (None) – a tag or iterable of tags of samples to select
-
property
selected_labels
¶ A list of labels currently selected in the App.
Items are dictionaries with the following keys:
label_id
: the ID of the labelsample_id
: the ID of the sample containing the labelfield
: the field name containing the labelframe_number
: the frame number containing the label (only applicable to video samples)
-
select_labels
(labels: Optional[List[dict]] = None, ids: Optional[Union[str, Iterable[str]]] = None, tags: Optional[Union[str, Iterable[str]]] = None, fields: Optional[Union[str, Iterable[str]]] = None) → None¶ Selects the specified labels in the current view in the App.
This method uses the same interface as
fiftyone.core.collections.SampleCollection.select_labels()
to specify the labels to select.- Parameters
labels (None) – a list of dicts specifying the labels to select
ids (None) – an ID or iterable of IDs of the labels to select
tags (None) – a tag or iterable of tags of labels to select
fields (None) – a field or iterable of fields from which to select
-
clear_selected_labels
() → None¶ Clears the currently selected labels, if any.
-
tag_selected_samples
(tag: str) → None¶ Adds the tag to the currently selected samples, if necessary.
The currently selected labels are
Session.selected
.- Parameters
tag – a tag
-
untag_selected_samples
(tag: str) → None¶ Removes the tag from the currently selected samples, if necessary.
The currently selected labels are
Session.selected
.- Parameters
tag – a tag
-
tag_selected_labels
(tag: str) → None¶ Adds the tag to the currently selected labels, if necessary.
The currently selected labels are
Session.selected_labels
.- Parameters
tag – a tag
-
untag_selected_labels
(tag: str) → None¶ Removes the tag from the currently selected labels, if necessary.
The currently selected labels are
Session.selected_labels
.- Parameters
tag – a tag
-
property
selected_view
¶ A
fiftyone.core.view.DatasetView
containing the currently selected content in the App.The selected view is defined as follows:
If both samples and labels are selected, the view will contain only the
selected_labels
from within theselected
samplesIf samples are selected, the view will only contain the
selected
samplesIf labels are selected, the view will only contain the
selected_labels
If no samples or labels are selected, the view will be
None
-
summary
() → str¶ Returns a string summary of the session.
- Returns
a string summary
-
open
() → None¶ Opens the App, if necessary.
The behavior of this method depends on your context:
Notebooks: calls
Session.show()
to open a new App window in the output of your current cellOther (non-remote): opens the App in a new browser tab
-
open_tab
() → None¶ Opens the App in a new tab of your browser.
This method can be called from Jupyter notebooks to override the default location of the App.
-
show
(height: int = None) → None¶ Opens the App in the output of the current notebook cell.
This method has no effect in non-notebook contexts.
- Parameters
height (None) – a height, in pixels, for the App
-
no_show
() → fiftyone.core.utils.SetAttributes¶ Returns a context manager that temporarily prevents new App instances from being opened in the current notebook cell when methods are run that normally would show new App windows.
This method has no effect in non-notebook contexts.
Examples:
import fiftyone as fo dataset = foz.load_zoo_dataset("quickstart") session = fo.launch_app(dataset) # (new cell) # Opens a new App instance session.view = dataset.take(100) # (new cell) # Does not open a new App instance with session.no_show(): session.view = dataset.take(100)
- Returns
a context manager
-
wait
(wait: float = 3) → None¶ Blocks execution until the App is closed by the user.
All connected windows (tabs) must be closed before this method will unblock.
- Parameters
wait (3) – the number of seconds to wait for a new App connection before returning if all connections are lost. If negative, the process will wait forever, regardless of connections
-
close
() → None¶ Closes the session and terminates the App, if necessary.
-
freeze
() → None¶ Screenshots the active App cell, replacing it with a static image.
Only applicable to notebook contexts.