From 3e166a1c3cf2f5e0f80e705d9f1332ce571fd8aa Mon Sep 17 00:00:00 2001 From: bacetiner Date: Tue, 5 Nov 2024 19:59:20 -0800 Subject: [PATCH 1/3] bc - Updated example with additional image downloading options --- .../image_processor/chimney_detector.ipynb | 534 +++++++++--------- 1 file changed, 254 insertions(+), 280 deletions(-) diff --git a/examples/image_processor/chimney_detector.ipynb b/examples/image_processor/chimney_detector.ipynb index 07a2396..cddc997 100644 --- a/examples/image_processor/chimney_detector.ipynb +++ b/examples/image_processor/chimney_detector.ipynb @@ -1,287 +1,261 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "view-in-github" + }, + "source": [ + "\n", + " \n", + " Open in\n", + " \"Open\n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \"Open\n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \"Open\n", + " \n", + "" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "aFu-PB0j9_-s" + }, + "source": [ + "## **Install BRAILS++**\n", + "BRAILS++ is not yet available on PyPi. The following line installs the latest version from the GitHub repository using `pip`." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { "colab": { - "provenance": [], - "authorship_tag": "ABX9TyOn1ecsEsZM9q63G3hYyP2O", - "include_colab_link": true - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" + "base_uri": "https://localhost:8080/" }, - "language_info": { - "name": "python" + "id": "KkujirTi9oZu", + "outputId": "56ef57fa-739d-4cea-f16f-06768c53133a" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting git+https://github.com/NHERI-SimCenter/BrailsPlusPlus\n", + " Cloning https://github.com/NHERI-SimCenter/BrailsPlusPlus to /tmp/pip-req-build-6s_qdstc\n", + " Running command git clone --filter=blob:none --quiet https://github.com/NHERI-SimCenter/BrailsPlusPlus /tmp/pip-req-build-6s_qdstc\n", + " Resolved https://github.com/NHERI-SimCenter/BrailsPlusPlus to commit 5fb904699fc635595d85a27b61f0748ecc584021\n", + " Preparing metadata (setup.py) ... \u001b[?25lerror\n", + " \u001b[1;31merror\u001b[0m: \u001b[1msubprocess-exited-with-error\u001b[0m\n", + " \n", + " \u001b[31m×\u001b[0m \u001b[32mpython setup.py egg_info\u001b[0m did not run successfully.\n", + " \u001b[31m│\u001b[0m exit code: \u001b[1;36m1\u001b[0m\n", + " \u001b[31m╰─>\u001b[0m \u001b[31m[12 lines of output]\u001b[0m\n", + " \u001b[31m \u001b[0m Traceback (most recent call last):\n", + " \u001b[31m \u001b[0m File \"\", line 2, in \n", + " \u001b[31m \u001b[0m File \"\", line 34, in \n", + " \u001b[31m \u001b[0m File \"/tmp/pip-req-build-6s_qdstc/setup.py\", line 4, in \n", + " \u001b[31m \u001b[0m import brails\n", + " \u001b[31m \u001b[0m File \"/tmp/pip-req-build-6s_qdstc/brails/__init__.py\", line 44, in \n", + " \u001b[31m \u001b[0m from .utils.importer import Importer\n", + " \u001b[31m \u001b[0m File \"/tmp/pip-req-build-6s_qdstc/brails/utils/__init__.py\", line 44, in \n", + " \u001b[31m \u001b[0m from .geo_tools import GeoTools\n", + " \u001b[31m \u001b[0m File \"/tmp/pip-req-build-6s_qdstc/brails/utils/geo_tools.py\", line 50, in \n", + " \u001b[31m \u001b[0m import matplotlib.pyplot as plt\n", + " \u001b[31m \u001b[0m ModuleNotFoundError: No module named 'matplotlib'\n", + " \u001b[31m \u001b[0m \u001b[31m[end of output]\u001b[0m\n", + " \n", + " \u001b[1;35mnote\u001b[0m: This error originates from a subprocess, and is likely not a problem with pip.\n", + "\u001b[1;31merror\u001b[0m: \u001b[1mmetadata-generation-failed\u001b[0m\n", + "\n", + "\u001b[31m×\u001b[0m Encountered error while generating package metadata.\n", + "\u001b[31m╰─>\u001b[0m See above for output.\n", + "\n", + "\u001b[1;35mnote\u001b[0m: This is an issue with the package mentioned above, not pip.\n", + "\u001b[1;36mhint\u001b[0m: See above for details.\n", + "\u001b[?25hNote: you may need to restart the kernel to use updated packages.\n" + ] } + ], + "source": [ + "pip install git+https://github.com/NHERI-SimCenter/BrailsPlusPlus" + ] }, - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "\"Open" - ] - }, - { - "cell_type": "markdown", - "source": [ - "## **Install BRAILS++**\n", - "BRAILS++ is not yet available on PyPi. The following line installs the latest version from the GitHub repository using `pip`." - ], - "metadata": { - "id": "aFu-PB0j9_-s" - } - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "KkujirTi9oZu", - "outputId": "56ef57fa-739d-4cea-f16f-06768c53133a" - }, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Collecting git+https://github.com/NHERI-SimCenter/BrailsPlusPlus\n", - " Cloning https://github.com/NHERI-SimCenter/BrailsPlusPlus to /tmp/pip-req-build-er4rdzrd\n", - " Running command git clone --filter=blob:none --quiet https://github.com/NHERI-SimCenter/BrailsPlusPlus /tmp/pip-req-build-er4rdzrd\n" - ] - }, - { - "output_type": "stream", - "name": "stderr", - "text": [ - "Exception in thread Thread-5 (attachment_entry):\n", - "Traceback (most recent call last):\n", - " File \"/usr/local/lib/python3.10/dist-packages/debugpy/server/api.py\", line 237, in listen\n", - " sock, _ = endpoints_listener.accept()\n", - " File \"/usr/lib/python3.10/socket.py\", line 293, in accept\n", - " fd, addr = self._accept()\n", - "TimeoutError: timed out\n", - "\n", - "During handling of the above exception, another exception occurred:\n", - "\n", - "Traceback (most recent call last):\n", - " File \"/usr/lib/python3.10/threading.py\", line 1016, in _bootstrap_inner\n", - " self.run()\n", - " File \"/usr/lib/python3.10/threading.py\", line 953, in run\n", - " self._target(*self._args, **self._kwargs)\n", - " File \"/usr/local/lib/python3.10/dist-packages/google/colab/_debugpy.py\", line 52, in attachment_entry\n", - " debugpy.listen(_dap_port)\n", - " File \"/usr/local/lib/python3.10/dist-packages/debugpy/public_api.py\", line 31, in wrapper\n", - " return wrapped(*args, **kwargs)\n", - " File \"/usr/local/lib/python3.10/dist-packages/debugpy/server/api.py\", line 143, in debug\n", - " log.reraise_exception(\"{0}() failed:\", func.__name__, level=\"info\")\n", - " File \"/usr/local/lib/python3.10/dist-packages/debugpy/server/api.py\", line 141, in debug\n", - " return func(address, settrace_kwargs, **kwargs)\n", - " File \"/usr/local/lib/python3.10/dist-packages/debugpy/server/api.py\", line 251, in listen\n", - " raise RuntimeError(\"timed out waiting for adapter to connect\")\n", - "RuntimeError: timed out waiting for adapter to connect\n" - ] - }, - { - "output_type": "stream", - "name": "stdout", - "text": [ - " Resolved https://github.com/NHERI-SimCenter/BrailsPlusPlus to commit 1c734ed6a87a26d0a25c180c2df41ca6400ddfc4\n", - " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", - "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (2.2.2)\n", - "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (2.32.3)\n", - "Requirement already satisfied: wget in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (3.2)\n", - "Requirement already satisfied: shapely in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (2.0.6)\n", - "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (4.66.5)\n", - "Requirement already satisfied: torch>=1.12 in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (2.4.1+cu121)\n", - "Requirement already satisfied: torchvision>0.13 in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (0.19.1+cu121)\n", - "Requirement already satisfied: Pillow in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (10.4.0)\n", - "Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (3.7.1)\n", - "Requirement already satisfied: seaborn in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (0.13.2)\n", - "Requirement already satisfied: plotly in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (5.24.1)\n", - "Requirement already satisfied: ftfy in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (6.3.0)\n", - "Requirement already satisfied: supervision in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (0.24.0)\n", - "Requirement already satisfied: opencv-python in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (4.10.0.84)\n", - "Requirement already satisfied: addict in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (2.4.0)\n", - "Requirement already satisfied: yapf in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (0.40.2)\n", - "Requirement already satisfied: timm in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (1.0.9)\n", - "Requirement already satisfied: transformers in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (4.44.2)\n", - "Requirement already satisfied: pycocotools in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (2.0.8)\n", - "Requirement already satisfied: Cython in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (3.0.11)\n", - "Requirement already satisfied: webcolors in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (24.8.0)\n", - "Requirement already satisfied: typing in /usr/local/lib/python3.10/dist-packages (from brails==4.0) (3.7.4.3)\n", - "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch>=1.12->brails==4.0) (3.16.1)\n", - "Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.10/dist-packages (from torch>=1.12->brails==4.0) (4.12.2)\n", - "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch>=1.12->brails==4.0) (1.13.3)\n", - "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch>=1.12->brails==4.0) (3.4)\n", - "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch>=1.12->brails==4.0) (3.1.4)\n", - "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch>=1.12->brails==4.0) (2024.6.1)\n", - "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from torchvision>0.13->brails==4.0) (1.26.4)\n", - "Requirement already satisfied: wcwidth in /usr/local/lib/python3.10/dist-packages (from ftfy->brails==4.0) (0.2.13)\n", - "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->brails==4.0) (1.3.0)\n", - "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->brails==4.0) (0.12.1)\n", - "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->brails==4.0) (4.54.1)\n", - "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->brails==4.0) (1.4.7)\n", - "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->brails==4.0) (24.1)\n", - "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->brails==4.0) (3.1.4)\n", - "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib->brails==4.0) (2.8.2)\n", - "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->brails==4.0) (2024.2)\n", - "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.10/dist-packages (from pandas->brails==4.0) (2024.2)\n", - "Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from plotly->brails==4.0) (9.0.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->brails==4.0) (3.4.0)\n", - "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->brails==4.0) (3.10)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->brails==4.0) (2.2.3)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->brails==4.0) (2024.8.30)\n", - "Requirement already satisfied: defusedxml<0.8.0,>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from supervision->brails==4.0) (0.7.1)\n", - "Requirement already satisfied: pyyaml>=5.3 in /usr/local/lib/python3.10/dist-packages (from supervision->brails==4.0) (6.0.2)\n", - "Requirement already satisfied: scipy<2.0.0,>=1.10.0 in /usr/local/lib/python3.10/dist-packages (from supervision->brails==4.0) (1.13.1)\n", - "Requirement already satisfied: huggingface_hub in /usr/local/lib/python3.10/dist-packages (from timm->brails==4.0) (0.24.7)\n", - "Requirement already satisfied: safetensors in /usr/local/lib/python3.10/dist-packages (from timm->brails==4.0) (0.4.5)\n", - "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers->brails==4.0) (2024.9.11)\n", - "Requirement already satisfied: tokenizers<0.20,>=0.19 in /usr/local/lib/python3.10/dist-packages (from transformers->brails==4.0) (0.19.1)\n", - "Requirement already satisfied: importlib-metadata>=6.6.0 in /usr/local/lib/python3.10/dist-packages (from yapf->brails==4.0) (8.5.0)\n", - "Requirement already satisfied: platformdirs>=3.5.1 in /usr/local/lib/python3.10/dist-packages (from yapf->brails==4.0) (4.3.6)\n", - "Requirement already satisfied: tomli>=2.0.1 in /usr/local/lib/python3.10/dist-packages (from yapf->brails==4.0) (2.0.2)\n", - "Requirement already satisfied: zipp>=3.20 in /usr/local/lib/python3.10/dist-packages (from importlib-metadata>=6.6.0->yapf->brails==4.0) (3.20.2)\n", - "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib->brails==4.0) (1.16.0)\n", - "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch>=1.12->brails==4.0) (3.0.1)\n", - "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy->torch>=1.12->brails==4.0) (1.3.0)\n" - ] - } - ], - "source": [ - "pip install git+https://github.com/NHERI-SimCenter/BrailsPlusPlus" - ] - }, - { - "cell_type": "markdown", - "source": [ - "## **Import ImageSet and Importer Methods of BRAILS++**\n", - "BRAILS++ offers various Artificial Intelligence-powered modules for predicting building and infrastructure attributes from images, such as the RoofShapeClassifier demonstrated in this example.\n", - "\n", - "The `Importer` class provides the main methods to load these modules. The `ImageSet` class and BRAILS++ scrapers dedicated to this purpose can be utilized to get the images needed to predict attributes. This example will illustrate both approaches." - ], - "metadata": { - "id": "sqCVhpcm-ePA" - } - }, - { - "cell_type": "code", - "source": [ - "from brails.types.image_set import ImageSet\n", - "from brails.utils.utils import Importer" - ], - "metadata": { - "id": "hKRsVFR4-M1b" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "## **Load Street-Level Imagery: (Option 1) Download Imagery by Specifying the Region Name**\n", - "The `ChimneyDetector` class is created to identify the roof types of buildings using satellite or aerial imagery. In this option, BRAILS++ retrieves the required imagery by following the steps below.\n", - "1. Call the `RegionBoundary` class with the necessary details to specify the region of interest. In this example, bird's eye imagery of buildings in Atlantic County, NJ are downloaded. Therefore, the required information includes the `type` of information provided and the `data` itself, which are the `locationName` and `Atlantic County, NJ`.\n", - "2. Download the footprint inventory for the `RegionBoundary` saved in `region_boundary_object` by downloading the OpenStreetMap footprint data through the `OSM_FootprintScraper`. The only information required to initialize `OSM_FootprintScraper` is the desired output unit for `length`, which, in this case, is `ft` . The output of `OSM_FootprintScraper` is an `AssetInventory` saved in `osm_fp_inventory`.\n", - "3. Get a randomly selected `100` building subset of the footprint inventory obtained using `OSM_FootprintScraper`. This subset is obtained using the `get_random_sample` method of an `AssetInventory` object and is stored in `alameda_subset`. For this example, the random seed is set to `40` for reproducability of the results.\n", - "4. Get the street-level imagery for the selected subset\n" - ], - "metadata": { - "id": "WWtc71tt-rbt" - } - }, - { - "cell_type": "code", - "source": [ - "# Select a region and create its RegionBoundary:\n", - "region_data = {\"type\": \"locationName\",\n", - " \"data\": \"Atlantic County, NJ\"}\n", - "region_boundary_class = importer.get_class(\"RegionBoundary\")\n", - "region_boundary_object = region_boundary_class(region_data)\n", - "\n", - "osm_fp_class = importer.get_class(\"OSM_FootprintScraper\")\n", - "osm_fp_data = {\"length\": \"ft\"}\n", - "footprint_scraper = osm_fp_class(osm_fp_data)\n", - "atlantic_fp = footprint_scraper.get_footprints(region_boundary_object)\n", - "\n", - "# Subsample from the extracted assets to keep the image downloading step quick.\n", - "# Here, we are randomly sampling 20 buildings using a random seed value of 40:\n", - "atlantic_fp_subset = atlantic_fp.get_random_sample(100, 40)\n", - "\n", - "# Get aerial imagery for the selected subset using GoogleSatellite:\n", - "google_street_class = importer.get_class(\"GoogleStreet\")\n", - "google_street = google_street_class()\n", - "images_street = google_street.get_images(\n", - " atlantic_fp_subset, \"tmp/street/\")" - ], - "metadata": { - "id": "nAYEbgmj6GxA" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "## **Predict Building Occupancies Using ChimneyDetector Module**\n", - "`ChimneyDetector` includes a pre-trained EfficientNet_V2_M model that has been trained on a custom dataset of 100,000 images. This model is capable of idnetifying existence of chimneys." - ], - "metadata": { - "id": "-Ce9IL05AMqD" - } - }, - { - "cell_type": "code", - "source": [ - "importer = Importer()\n", - "chimney_detector_class = importer.get_class('ChimneyDetector')\n", - "chimney_detector = chimney_detector_class()\n", - "predictions = chimney_detector.predict(images_street)" - ], - "metadata": { - "id": "XWG53_xtFa_F" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "## **Load Street Imagery**\n", - "The `ChimneyDetector` class is designed to identify roof types of buildings based on aerial imagery. In this example, we will load images from the `examples/image_processor/images/street_easy` directory of BRAILS++ to showcase how to use the `ChimneyDetector`.\n", - "\n", - "To load these images, you first need to initialize an `ImageSet` object, which will be assigned to aerial_images. This object can then load the target images by scanning the specified directory using the set_directory method. The second argument in set_directory is necessary for loading the images; otherwise, the default behavior of `ImageSet` is to simply set the directory to the string value provided in the first argument (in this case, `images/street`)." - ], - "metadata": { - "id": "JunwEpGi6MWg" - } - }, - { - "cell_type": "markdown", - "source": [ - "## **Retrain Default ChimneyDetector Module**" - ], - "metadata": { - "id": "oKSebGtqGEb_" - } - }, + { + "cell_type": "markdown", + "metadata": { + "id": "sqCVhpcm-ePA" + }, + "source": [ + "## **Import ImageSet and Importer Methods of BRAILS++**\n", + "BRAILS++ offers various Artificial Intelligence-powered modules for predicting building and infrastructure attributes from images, such as the `ChimneyDetector` demonstrated in this example.\n", + "\n", + "The `Importer` class provides the main methods to load these modules. To gather the images needed for attribute prediction, users can use the ImageSet class or BRAILS++ scrapers, which facilitate automated asset geometry and image retrieval. This example illustrates both methods for sourcing imagery for use with the `ChimneyDetector` module." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "hKRsVFR4-M1b" + }, + "outputs": [ { - "cell_type": "code", - "source": [ - "chimney_detector.retrain(images_street)" - ], - "metadata": { - "id": "dNLUWp3IEq74" - }, - "execution_count": null, - "outputs": [] + "ename": "ModuleNotFoundError", + "evalue": "No module named 'brails'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbrails\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Importer\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbrails\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtypes\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mimage_set\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ImageSet\n", + "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'brails'" + ] } - ] -} \ No newline at end of file + ], + "source": [ + "from brails import Importer\n", + "from brails.types.image_set import ImageSet" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WWtc71tt-rbt" + }, + "source": [ + "## **Load Street-Level Imagery: (Option 1) Download Imagery by Specifying the Region Name**\n", + "The `ChimneyDetector` class is created to identify the existence of chimneys in buildings from street-level imagery. In this option, BRAILS++ retrieves the required imagery by following the steps below.\n", + "1. Call the `RegionBoundary` class with the necessary details to specify the region of interest. In this example, street-level imagery of buildings in Atlantic County, NJ, are downloaded. Therefore, the required information includes the `type` of information provided and the `data` itself, which are the `locationName` and `Atlantic County, NJ`.\n", + "\n", + "2. Download the footprint inventory for the `RegionBoundary` saved in `region_boundary_object` by downloading the OpenStreetMap footprint data through the `OSM_FootprintScraper`. The only information required to initialize `OSM_FootprintScraper` is the desired output unit for `length`, which, in this case, is `ft`. The output of `OSM_FootprintScraper` is an `AssetInventory` saved in `atlantic_fp`.\n", + "\n", + "3. Get a randomly selected `100` building subset of the footprint inventory obtained using `OSM_FootprintScraper`. This subset is obtained using the `get_random_sample` method of an `AssetInventory` object and is stored in `atlantic_fp_subset`. For this example, the random seed is set to `40` for reproducibility of the results.\n", + "\n", + "4. Get the street-level imagery for the selected subset using `get_images` method of `GoogleStreet` module. `get_images` requires two inputs 1) AssetInventory for which the images will be retrieved (in this example, `atlantic_fp_subset`) and 2) the path to the folder where the retrieved images will be saved, which in this case is `tmp/street/`.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "nAYEbgmj6GxA" + }, + "outputs": [], + "source": [ + "# Select a region and create its RegionBoundary:\n", + "region_data = {\"type\": \"locationName\",\n", + " \"data\": \"Atlantic County, NJ\"}\n", + "region_boundary_class = importer.get_class(\"RegionBoundary\")\n", + "region_boundary_object = region_boundary_class(region_data)\n", + "\n", + "osm_fp_class = importer.get_class(\"OSM_FootprintScraper\")\n", + "osm_fp_data = {\"length\": \"ft\"}\n", + "footprint_scraper = osm_fp_class(osm_fp_data)\n", + "atlantic_fp = footprint_scraper.get_footprints(region_boundary_object)\n", + "\n", + "# Subsample from the extracted assets to keep the image downloading step quick.\n", + "# Here, we are randomly sampling 20 buildings using a random seed value of 40:\n", + "atlantic_fp_subset = atlantic_fp.get_random_sample(100, 40)\n", + "\n", + "# Get aerial imagery for the selected subset using GoogleSatellite:\n", + "google_street_class = importer.get_class(\"GoogleStreet\")\n", + "google_street = google_street_class()\n", + "images_street = google_street.get_images(\n", + " atlantic_fp_subset, 'tmp/street/')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-Ce9IL05AMqD" + }, + "source": [ + "## **Predict Existence of Chimneys Using the ChimneyDetector Module**\n", + "`ChimneyDetector` includes a pre-trained EfficientNet_V2_M model that has been trained on a custom dataset of 100,000 images. This model is capable of idnetifying existence of chimneys." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "XWG53_xtFa_F" + }, + "outputs": [], + "source": [ + "importer = Importer()\n", + "chimney_detector_class = importer.get_class('ChimneyDetector')\n", + "chimney_detector = chimney_detector_class()\n", + "predictions = chimney_detector.predict(images_street)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JunwEpGi6MWg" + }, + "source": [ + "## **Load Street Imagery**\n", + "The `ChimneyDetector` class is designed to identify roof types of buildings based on aerial imagery. In this example, we will load images from the `examples/image_processor/images/street_easy` directory of BRAILS++ to showcase how to use the `ChimneyDetector`.\n", + "\n", + "To load these images, you first need to initialize an `ImageSet` object, which will be assigned to aerial_images. This object can then load the target images by scanning the specified directory using the set_directory method. The second argument in set_directory is necessary for loading the images; otherwise, the default behavior of `ImageSet` is to simply set the directory to the string value provided in the first argument (in this case, `images/street`)." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "oKSebGtqGEb_" + }, + "source": [ + "## **Retrain Default ChimneyDetector Module**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "dNLUWp3IEq74" + }, + "outputs": [], + "source": [ + "chimney_detector.retrain(images_street)" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyOn1ecsEsZM9q63G3hYyP2O", + "include_colab_link": true, + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.10" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From f82a4dc409c29651bb5c9932f43dff0b3a7cf147 Mon Sep 17 00:00:00 2001 From: bacetiner Date: Wed, 6 Nov 2024 10:47:35 -0800 Subject: [PATCH 2/3] bc - Cleaned Filter abstract class --- brails/filters/filter.py | 81 ++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/brails/filters/filter.py b/brails/filters/filter.py index 3256720..b939324 100644 --- a/brails/filters/filter.py +++ b/brails/filters/filter.py @@ -1,43 +1,86 @@ -from abc import ABC, abstractmethod -from brails.types.image_set import ImageSet +# Copyright (c) 2024 The Regents of the University of California +# +# This file is part of BRAILS++. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# You should have received a copy of the BSD 3-Clause License along with +# BRAILS++. If not, see . +# +# Contributors: +# Frank McKenna +# Barbaros Cetiner +# +# Last updated: +# 11-06-2024 """ -This module defines abstract filter class +This module defines abstract filter class. .. autosummary:: Filter """ +from abc import ABC, abstractmethod +from brails.types.image_set import ImageSet + + class Filter(ABC): """ - Abstract base class representing a class that filters an ImageSet + Abstract base class for filtering an ImageSet. - Methods: - __init__(dict): Constructor - get_footprints(location): An abstract method to return the footprint given a location + Methods: + filter(images, dir_path): Filters the ImageSet based on specific + criteria. """ - def __init__(self, input_data: dict): + """ + Initialize the Filter with the provided input. + + Args: + input_data (dict): Configuration or parameters required for + filtering. + """ self.input_data = input_data - + @abstractmethod - def filter(self, images: ImageSet, dir_path: str) ->ImageSet: + def filter(self, images: ImageSet, dir_path: str) -> ImageSet: """ - An abstract class that must be implemented by subclasses. + Abstract class that must be implemented by subclasses. This method will be used by the caller to obtain a filtered ImageSet + and save the output in a specified directory. Args: - image_set (ImageSet): - The input ImageSet to be filtered - dir_path - The path to output dir where filtered images are to be placed + images (ImageSet): The ImageSet to filter. + dir_path (str): Path to the output directory for filtered images. Returns: - ImageSet: - The filtered set of images - + ImageSet: The filtered set of images. """ - pass From c3f36d9257da158a8afd7c25a876b897905b32c7 Mon Sep 17 00:00:00 2001 From: bacetiner Date: Wed, 6 Nov 2024 11:18:57 -0800 Subject: [PATCH 3/3] bc - Updated example Python scripts --- examples/footprint/brails_footprint.py | 125 +++++++++------- .../image_downloads/brails_download_images.py | 6 +- examples/image_filters/brails_filters.py | 140 +++++++++++------- .../brails_image_classifier.py | 59 ++++++-- .../image_processor/brails_object_detector.py | 51 ++++++- 5 files changed, 262 insertions(+), 119 deletions(-) diff --git a/examples/footprint/brails_footprint.py b/examples/footprint/brails_footprint.py index e10faaa..23ee436 100644 --- a/examples/footprint/brails_footprint.py +++ b/examples/footprint/brails_footprint.py @@ -1,72 +1,97 @@ -# Written: fmk 4/23 -# License: BSD-2 +# Copyright (c) 2024 The Regents of the University of California +# +# This file is part of BRAILS++. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# You should have received a copy of the BSD 3-Clause License along with +# BRAILS++. If not, see . +# +# Contributors: +# Frank McKenna +# Barbaros Cetiner +# +# Last updated: +# 11-06-2024 """ - Purpose: Testing Importer and get_footprints methods -""" - -import sys +Example demonstrating BRAILS' automated footprint downloading capabilities. -sys.path.insert(1, "../../") - -from brails.utils.utils import Importer + Purpose: Testing 1) get_class method of Importer + 2) get_footprints method of OSM_FootprintScraper, + MS_FootprintScraper, and USA_FootprintScraper modules + 3) get_random_sample of AssetInventory +""" -# create an Import to get the classes +from brails import Importer +# create an Importer object to fetch BRAILS++ classes: importer = Importer() -# -# specify the BoundaryRegion -# - +# Specify the BoundaryRegion: -region_data = {"type": "locationName", "data": "Tiburon, CA"} -region_boundary_class = importer.get_class("RegionBoundary") +region_data = {'type': 'locationName', 'data': 'Tiburon, CA'} +region_boundary_class = importer.get_class('RegionBoundary') region_boundary_object = region_boundary_class(region_data) -# -# Get Footprints using OSM -# +# Get Footprints using OSM: +print('Trying OSM_FootprintsScraper...') -print("Trying OSM_FootprintsScraper ...") - -osm_class = importer.get_class("OSM_FootprintScraper") -osm_data = {"length": "ft"} +osm_class = importer.get_class('OSM_FootprintScraper') +osm_data = {'length': 'ft'} instance1 = osm_class(osm_data) osm_inventory = instance1.get_footprints(region_boundary_object) -print("num assets OSM", len(osm_inventory.inventory)) +print('Number of assets in OSM', len(osm_inventory.inventory)) -# -# Get Footprints using Microsofts Database -# -print("Trying Microsoft Footprint Database ...") -ms_class = importer.get_class("MS_FootprintScraper") -ms_data = {"length": "ft"} -instance3 = ms_class(ms_data) -ms_inventory = instance3.get_footprints(region_boundary_object) +# Get Footprints using Microsoft Footprints Database: +print('Trying Microsoft Footprint Database...') +ms_class = importer.get_class('MS_FootprintScraper') +ms_data = {'length': 'ft'} +instance2 = ms_class(ms_data) +ms_inventory = instance2.get_footprints(region_boundary_object) -print("num assets Microsoft", len(ms_inventory.inventory)) +print('Number of assets in Microsoft Footprint Database', + len(ms_inventory.inventory)) -# -# Get Footprints using USA Structures -# - +# Get Footprints using USA Structures data: +print('Trying USA_FootprintsScraper...') +usa_class = importer.get_class('USA_FootprintScraper') +usa_data = {'length': 'ft'} +instance3 = usa_class(usa_data) +usa_inventory = instance3.get_footprints(region_boundary_object) -print("Trying USA_FootprintsScraper ...") -usa_class = importer.get_class("USA_FootprintScraper") -usa_data = {"length": "ft"} -instance2 = usa_class(usa_data) -usa_inventory = instance2.get_footprints(region_boundary_object) +print('Number of assets in USA Structures', len(usa_inventory.inventory)) -print("num assets USA", len(usa_inventory.inventory)) - -# -# Test obtaining a smaller subset of random values, -# method used as we will not always want to get all the images -# -small_inventory = usa_inventory.get_random_sample(4, 200) -print("num assets USA subset", len(small_inventory.inventory)) +# Obtain a smaller subset of random values, as we will not always want to get +# all the images: +print('\nGetting a subset of the USA footprints...') +small_inventory = usa_inventory.get_random_sample(10, 200) +print('Number of assets in the subset', len(small_inventory.inventory)) diff --git a/examples/image_downloads/brails_download_images.py b/examples/image_downloads/brails_download_images.py index 85b4407..1d9ef05 100644 --- a/examples/image_downloads/brails_download_images.py +++ b/examples/image_downloads/brails_download_images.py @@ -36,7 +36,7 @@ # Barbaros Cetiner # # Last updated: -# 10-24-2024 +# 11-06-2024 """ Example showcasing BRAILS' image downloading capabilities. @@ -60,7 +60,9 @@ if os.path.exists(API_KEY_DIR): with open(API_KEY_DIR, 'r', encoding='utf-8') as file: api_key = file.readline().strip() # Read first line & strip whitespace - +else: + raise FileNotFoundError('API key file not found. Please ensure the file' + f' exists at: {API_KEY_DIR}') # Create the importer: importer = Importer() diff --git a/examples/image_filters/brails_filters.py b/examples/image_filters/brails_filters.py index 318f5d6..77f43ba 100644 --- a/examples/image_filters/brails_filters.py +++ b/examples/image_filters/brails_filters.py @@ -1,78 +1,114 @@ -# Written: fmk 4/23 -# License: BSD-2 +# Copyright (c) 2024 The Regents of the University of California +# +# This file is part of BRAILS++. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# You should have received a copy of the BSD 3-Clause License along with +# BRAILS++. If not, see . +# +# Contributors: +# Frank McKenna +# Barbaros Cetiner +# +# Last updated: +# 11-06-2024 """ - Purpose: Testing Importer and get_footprints methods +Example showing the use of BRAILS module that crops building images from panos. + + Purpose: Testing 1) get_class method of Importer + 2) get_footprints method of USA_FootprintScraper module + 3) get_images and print_info methods of GoogleSatellite and + GoogleStreetview + 4) filter method of HouseView + 5) dir_path method of an ImageSet object """ -from brails.types.image_set import ImageSet -from brails.utils.utils import Importer import os -import sys +from pathlib import Path +from brails import Importer -# -# This script needs an Google API Key to run -# -- suggest placing in file, here apiKey.txt, if you plan to commit as you don't want to make a mistake -# -- apiKey.txt is in .gitignore so you have work to do to get it uploaded +# This script needs a Google API Key to run. +# We suggest placing your API key in file apiKey.txt in the same directory as +# this script if you plan to commit changes to this example. This way, you do +# not risk accidentally uploading your API key (apiKey.txt is in .gitignore, +# so you have work to do to get it uploaded) -apiKey = "" -if os.path.exists("apiKey.txt"): - with open("apiKey.txt", "r") as file: - apiKey = file.readline().strip() # Read the first line and strip whitespace +API_KEY_DIR = '../api_key.txt' +if os.path.exists(API_KEY_DIR): + with open(API_KEY_DIR, 'r', encoding='utf-8') as file: + api_key = file.readline().strip() # Read first line & strip whitespace +else: + raise FileNotFoundError('API key file not found. Please ensure the file' + f' exists at: {API_KEY_DIR}') -# -# create the importer -# - +# Create the importer: importer = Importer() -# select a region and create a RegionBoundary -# - -region_data = {"type": "locationName", "data": "Tiburon, CA"} -region_boundary_class = importer.get_class("RegionBoundary") +# Select a region and create its RegionBoundary: +region_data = {'type': 'locationName', 'data': 'Tiburon, CA'} +region_boundary_class = importer.get_class('RegionBoundary') region_boundary_object = region_boundary_class(region_data) -# -# get the inventory -# - -print("Trying USA_FootprintsScraper ...") +# Get AssetInventory for buildings in the defined region via +# USA_FootprintScraper: +print('Trying USA_FootprintsScraper...') -usa_class = importer.get_class("USA_FootprintScraper") -usa_data = {"length": "ft"} +usa_class = importer.get_class('USA_FootprintScraper') +usa_data = {'length': 'ft'} instance2 = usa_class(usa_data) usa_inventory = instance2.get_footprints(region_boundary_object) -print("num assets USA", len(usa_inventory.inventory)) +print('Total number of assets detected using FEMA USA Structures:', + len(usa_inventory.inventory)) -# -# Make the Inventory smaller as we are pulling images -# - (4 buildings with a seed of 200) - -small_inventory = usa_inventory.get_random_sample(20, 100) -print("num assets USA subset", len(small_inventory.inventory)) +# Subsample from the extracted assets to keep the image downloading step quick. +# Here, we are randomly sampling 10 buildings using a random seed value of 100: +small_inventory = usa_inventory.get_random_sample(10, 100) +print('\nTotal number of assets in the created subset:', + len(small_inventory.inventory)) -# -# Get street view images using GoogleStreetview -# - -google_input = {"apiKey": apiKey} -google_street_class = importer.get_class("GoogleStreetview") +# Get street level imagery for the selected subset using GoogleStreetview: +google_input = {'apiKey': api_key} +google_street_class = importer.get_class('GoogleStreetview') google_street = google_street_class(google_input) -images_street = google_street.get_images(small_inventory, "tmp/street/") +images_street = google_street.get_images(small_inventory, 'tmp/street/') images_street.print_info() -# -# now filter -# - -filter_house = importer.get_class("HouseView") +# Crop the obtained imagery such that they include just the buildings of +# interest: +filter_house = importer.get_class('HouseView') filter_data = {} -filter1 = filter_house(filter_data) -filter1.filter(images_street, "filtered_images") - +image_filter = filter_house(filter_data) +filtered_image_set = image_filter.filter(images_street, 'filtered_images') +print('\nCropped images are available in ', + Path(filtered_image_set.dir_path).resolve()) diff --git a/examples/image_processor/brails_image_classifier.py b/examples/image_processor/brails_image_classifier.py index 60b5d72..0f94760 100644 --- a/examples/image_processor/brails_image_classifier.py +++ b/examples/image_processor/brails_image_classifier.py @@ -1,11 +1,54 @@ -"""Purpose: Testing ImageSet, Importer and an aerial image classifier.""" +# Copyright (c) 2024 The Regents of the University of California +# +# This file is part of BRAILS++. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# You should have received a copy of the BSD 3-Clause License along with +# BRAILS++. If not, see . +# +# Contributors: +# Frank McKenna +# Barbaros Cetiner +# +# Last updated: +# 11-06-2024 -# Written: fmk 04/24 -# Modified: Barbaros Cetiner 10/24 -# Copyright BSD2 +""" +Example demonstrating use of aerial and street-level image classifiers. + + Purpose: Testing 1) get_class method of Importer + 2) set_directory and print_info methods of ImageSet objects + 3) predict methods of RoofShapeClassifier, + OccupancyClassifier, and NFloorVLM +""" from brails.types.image_set import ImageSet -from brails.utils import Importer +from brails import Importer importer = Importer() aerial_images = ImageSet() @@ -21,12 +64,6 @@ predictions = my_classifier.predict(aerial_images) print(predictions) -print('\nROOF SHAPE PREDICTIONS USING CLIP VLM:') -my_class = importer.get_class('RoofShapeVLM') -my_classifier = my_class() -predictions = my_classifier.predict(aerial_images) -print(predictions) - # Test importer and a couple of the street-level imagery classifiers: street_images.print_info() print('\nOCCUPANCY CLASS PREDICTIONS USING MODEL TRAINED ON CUSTOM DATASET:') diff --git a/examples/image_processor/brails_object_detector.py b/examples/image_processor/brails_object_detector.py index 0a3f10b..5eab84b 100644 --- a/examples/image_processor/brails_object_detector.py +++ b/examples/image_processor/brails_object_detector.py @@ -1,10 +1,53 @@ -"""Purpose: Testing ImageSet, Importer and an street-level detector.""" +# Copyright (c) 2024 The Regents of the University of California +# +# This file is part of BRAILS++. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# You should have received a copy of the BSD 3-Clause License along with +# BRAILS++. If not, see . +# +# Contributors: +# Barbaros Cetiner +# +# Last updated: +# 11-06-2024 -# Written: Barbaros Cetiner 09/24 -# Copyright BSD2 +""" +Example demonstrating use of street-level image detectors. + + Purpose: Testing 1) get_class method of Importer + 2) set_directory and print_info methods of ImageSet objects + 3) predict methods of NFloorDetector, ChimneyDetector, and + GarageDetector +""" from brails.types.image_set import ImageSet -from brails.utils.utils import Importer +from brails import Importer importer = Importer() street_images = ImageSet()