Exemple #1
0
def visualize(labels: Union[List[Label], List[Dict[str, Label]]],
              filepaths: Optional[List[str]] = None,
              wait: Optional[bool] = True,
              label_field: Optional[str] = "predictions",
              **kwargs) -> Optional[Session]:
    """Use the result of a FiftyOne serializer to visualize predictions in the
    FiftyOne App.

    Args:
        labels: Either a list of FiftyOne labels that will be applied to the
            corresponding filepaths provided with through `filepath` or
            `datamodule`. Or a list of dictionaries containing image/video
            filepaths and corresponding FiftyOne labels.
        filepaths: A list of filepaths to images or videos corresponding to the
            provided `labels`.
        wait: A boolean determining whether to launch the FiftyOne session and
            wait until the session is closed or whether to return immediately.
        label_field: The string of the label field in the FiftyOne dataset
            containing predictions
    """
    if not _FIFTYONE_AVAILABLE:
        raise ModuleNotFoundError("Please, `pip install fiftyone`.")
    if flash._IS_TESTING:
        return None

    # Flatten list if batches were used
    if all(isinstance(fl, list) for fl in labels):
        labels = list(chain.from_iterable(labels))

    if all(isinstance(fl, dict) for fl in labels):
        filepaths = [lab["filepath"] for lab in labels]
        labels = [lab["predictions"] for lab in labels]

    if filepaths is None:
        raise ValueError(
            "The `filepaths` argument is required if filepaths are not provided in `labels`."
        )

    dataset = fo.Dataset()
    if filepaths:
        dataset.add_labeled_images(
            list(zip(filepaths, labels)),
            LabeledImageTupleSampleParser(),
            label_field=label_field,
        )
    session = fo.launch_app(dataset, **kwargs)
    if wait:
        session.wait()
    return session
Exemple #2
0
def app_test():
	dataset = foz.load_zoo_dataset("quickstart")
	#dataset = foz.load_zoo_dataset("quickstart-video")
	#dataset = foz.load_zoo_dataset("cifar10")

	session = fo.launch_app(dataset, port=5151)
	#session.show()

	if False:
		# View the dataset in the App.
		session.dataset = dataset
	elif False:
		# Object patches.

		# Convert to ground truth patches.
		gt_patches = dataset.to_patches("ground_truth")
		print(gt_patches)

		# View patches in the App.
		session.view = gt_patches
	elif False:
		# Evaluation patches.

		# Evaluate 'predictions' w.r.t. labels in 'ground_truth' field.
		dataset.evaluate_detections("predictions", gt_field="ground_truth", eval_key="eval")

		# Convert to evaluation patches.
		eval_patches = dataset.to_evaluation_patches("eval")
		print(eval_patches)

		print(eval_patches.count_values("type"))

		# View patches in the App.
		session.view = eval_patches

	# Blocks execution until the App is closed.
	session.wait()
)
trainer.save_checkpoint("image_classification_model.pt")

# 5 Predict from checkpoint on data with ground truth
model = ImageClassifier.load_from_checkpoint("https://flash-weights.s3.amazonaws.com/image_classification_model.pt")
model.serializer = FiftyOneLabels(return_filepath=False)
datamodule = ImageClassificationData.from_fiftyone(predict_dataset=test_dataset)
predictions = trainer.predict(model, datamodule=datamodule)

predictions = list(chain.from_iterable(predictions))  # flatten batches

# 6 Add predictions to dataset
test_dataset.set_values("predictions", predictions)

# 7 Visualize labels in the App
session = fo.launch_app(test_dataset)

# 8 Evaluate your model
results = test_dataset.evaluate_classifications(
    "predictions",
    gt_field="ground_truth",
    eval_key="eval",
)
results.print_report()
plot = results.plot_confusion_matrix()
plot.show()

# Only when running this in a script
# Block until the FiftyOne App is closed
session.wait()
Exemple #4
0
def launch_fiftyone_app(coco_image_dir: str, coco_json_path: str):
    dataset = create_fiftyone_dataset_from_coco_file(coco_image_dir,
                                                     coco_json_path)
    session = fo.launch_app()
    session.dataset = dataset
    return session
Exemple #5
0
import fiftyone as fo
import fiftyone.zoo as foz

# Blog: https://blog.csdn.net/fengbingchun/article/details/121284157

# reference: https://voxel51.com/docs/fiftyone/tutorials/evaluate_detections.html
datasets = foz.list_zoo_datasets()
print("available datasets:", datasets)

dataset = foz.load_zoo_dataset("coco-2017", split="validation", dataset_name="evaluate-detections-tutorial")
dataset.persistent = True
session = fo.launch_app(dataset)

# print some information about the dataset
print("dataset info:", dataset)

# print a ground truth detection
sample = dataset.first()
print("ground truth:", sample.ground_truth.detections[0])

session.wait()
Exemple #6
0
import fiftyone as fo

# Load your FiftyOne dataset
dataset = ...

# Launch the app locally
# (if you're reading this from the app, you've already done this!)
session = fo.launch_app()

# Load a dataset
session.dataset = dataset

# Load a specific view into your dataset
session.view = view
Exemple #7
0
import fiftyone as fo

# Load your FiftyOne dataset
dataset = ...

# Launch the app that you'll connect to from your local machine
session = fo.launch_app(remote=True)

# Load a dataset
session.dataset = dataset

# Load a specific view into your dataset
session.view = view