diff --git a/.ci/unit_tests/python/__init_.py b/.ci/unit_tests/python/__init_.py new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index 1d90766..0d58204 100644 --- a/.gitignore +++ b/.gitignore @@ -1,29 +1,3 @@ -# Python # -########## -__pycache__/ -*.py[cod] -*$py.class -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - - # Compiled source # ################### *.com @@ -31,6 +5,7 @@ MANIFEST *.exe *.o *.so +*.dll # Packages # ############ @@ -82,12 +57,58 @@ bld/ *.suo *.user .vs/ -Alligator/Alligator.csproj.orig -Alligator/Alligator_BACKUP_9848.csproj -Alligator/Alligator_BASE_9848.csproj -Alligator/Alligator_LOCAL_9848.csproj -Alligator/Alligator_REMOTE_9848.csproj - -# Exceptions # -############## -!/lib/*.dll +/BHoM/Acoustic/Database + +# VScode environment files # +############################ +.vscode/ + +# Pycharm environment files # +############################# +.idea/ + +# Python related files # +######################## +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ \ No newline at end of file diff --git a/MachineLearning_Engine/Compute/Audio/PlayAudio.cs b/MachineLearning_Engine/Compute/Audio/PlayAudio.cs deleted file mode 100644 index 31605ee..0000000 --- a/MachineLearning_Engine/Compute/Audio/PlayAudio.cs +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; - -namespace BH.Engine.MachineLearning.Audio -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static void PlayAudio(Tensor audioTensor, int rate = 22050, bool run = false) - { - if (run) - BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "PlayAudio.play_numpy_audio", audioTensor, rate); - return; - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Audio/PlayAudio.py b/MachineLearning_Engine/Compute/Audio/PlayAudio.py deleted file mode 100644 index c5c824e..0000000 --- a/MachineLearning_Engine/Compute/Audio/PlayAudio.py +++ /dev/null @@ -1,28 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import sounddevice as sd - - -def play_numpy_audio(audio_numpy, rate): - sd.play(audio_numpy, samplerate=rate) - return diff --git a/MachineLearning_Engine/Compute/Audio/RecogniseSpeech.cs b/MachineLearning_Engine/Compute/Audio/RecogniseSpeech.cs deleted file mode 100644 index 466b367..0000000 --- a/MachineLearning_Engine/Compute/Audio/RecogniseSpeech.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; - -namespace BH.Engine.MachineLearning.Audio -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static Tensor RecogniseSpeech(string wavFile = "", bool run = false) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "RecogniseSpeech.infer", wavFile, run)); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Audio/RecogniseSpeech.py b/MachineLearning_Engine/Compute/Audio/RecogniseSpeech.py deleted file mode 100644 index e6c7f44..0000000 --- a/MachineLearning_Engine/Compute/Audio/RecogniseSpeech.py +++ /dev/null @@ -1,52 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import os -import sys -import at16k -import at16k.api - - -def infer(wav_file: str, run: bool): - if not run: - return "" - - os.environ['AT16K_RESOURCES_DIR'] = HOME - - # load models if necessary - global SPEECH_RECOGNITION_MODEL - if SPEECH_RECOGNITION_MODEL is None: - _download() - SPEECH_RECOGNITION_MODEL = at16k.api.SpeechToText(os.path.normpath("en_16k")) - - return audio_numpy - - -def _download(): - os.makedirs(HOME, exist_ok=True) - - sys.argv = ['download', 'en_16k'] - exec(open(at16k.download.__file__).read()) - return - -HOME = "C:\\ProgramData\\BHoM\\Extensions\\Python\\models\\audio\\at_16k\\" -SPEECH_RECOGNITION_MODEL = None diff --git a/MachineLearning_Engine/Compute/Audio/SynthesiseSpeech.cs b/MachineLearning_Engine/Compute/Audio/SynthesiseSpeech.cs deleted file mode 100644 index c7b061c..0000000 --- a/MachineLearning_Engine/Compute/Audio/SynthesiseSpeech.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; - -namespace BH.Engine.MachineLearning.Audio -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static Tensor SynthesiseSpeech(string text, bool gpu = false) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "SynthesiseSpeech.infer", text, gpu)); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Audio/SynthesiseSpeech.py b/MachineLearning_Engine/Compute/Audio/SynthesiseSpeech.py deleted file mode 100644 index 1cf7b72..0000000 --- a/MachineLearning_Engine/Compute/Audio/SynthesiseSpeech.py +++ /dev/null @@ -1,62 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import torch -import numpy as np - - -def infer(text: str, gpu: bool): - # check if cuda is avaliable - gpu = gpu and torch.cuda.is_avaliable() - - # accelerate on gpu if possible - device = "cuda" if gpu else "cpu" - - # load models if necessary - global WAVEGLOW - if WAVEGLOW is None: - WAVEGLOW = torch.hub.load('nvidia/DeepLearningExamples:torchhub', 'nvidia_waveglow') - WAVEGLOW = WAVEGLOW.remove_weightnorm(WAVEGLOW) - WAVEGLOW.eval() - - global TACOTRON2 - if TACOTRON2 is None: - TACOTRON2 = torch.hub.load('nvidia/DeepLearningExamples:torchhub', 'nvidia_tacotron2') - TACOTRON2.eval() - - WAVEGLOW = WAVEGLOW.to(device) - TACOTRON2 = TACOTRON2.to(device) - - # preprocess text sequence - sequence = np.array(TACOTRON2.text_to_sequence(text, ['english_cleaners']))[None, :] - sequence = torch.as_tensor(sequence, device=device, dtype=torch.int64) - - # compute output - with torch.no_grad(): - _, mel, _, _ = TACOTRON2.infer(sequence) - audio = WAVEGLOW.infer(mel) - audio_numpy = audio[0].data.cpu().numpy() - - return audio_numpy - -TACOTRON2 = None -WAVEGLOW = None diff --git a/MachineLearning_Engine/Compute/Audio/__init__ .py b/MachineLearning_Engine/Compute/Audio/__init__ .py deleted file mode 100644 index 48eb5d9..0000000 --- a/MachineLearning_Engine/Compute/Audio/__init__ .py +++ /dev/null @@ -1,25 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from . import PlayAudio -from . import SynthesiseSpeech -from . import RecogniseSpeech diff --git a/MachineLearning_Engine/Compute/Charts/Diurnal.cs b/MachineLearning_Engine/Compute/Charts/Diurnal.cs deleted file mode 100644 index 0e9d6bd..0000000 --- a/MachineLearning_Engine/Compute/Charts/Diurnal.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using System.Collections.Generic; -using BH.oM.Base.Attributes; - -namespace BH.Engine.MachineLearning.Charts -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static string PlotDiurnal(List annualValues, string savePath, string grouping = "Daily", List months = null, string title = null, string unit = null, string color = "black", string toneColor = "black", bool transparency = false, bool run = false) - { - if (!run) - return null; - - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "Diurnal.diurnal", annualValues, savePath, grouping, months, title, unit, color, toneColor, transparency).ToString(); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Charts/Diurnal.py b/MachineLearning_Engine/Compute/Charts/Diurnal.py deleted file mode 100644 index c36ef74..0000000 --- a/MachineLearning_Engine/Compute/Charts/Diurnal.py +++ /dev/null @@ -1,156 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import os -import numpy as np -import pandas as pd -import matplotlib -matplotlib.use("agg") -import matplotlib.pyplot as plt -from matplotlib.ticker import MaxNLocator - -ANNUAL_DATETIME = pd.date_range(start="2018-01-01 00:30:00", freq="60T", periods=8760, closed="left") - - -def diurnal(annual_values: np.ndarray, save_path: str, grouping: str="Daily", months: np.ndarray=range(1, 13), title: str=None, unit: str=None, color: str="black", tone_color: str="black", transparency=False): - """ Create a histogram with summary table for the data passed - - Parameters - ---------- - annual_values : np.ndarray - List of values to bin. - save_path : str - The full path where the plot will be saved. - grouping : str - The method of grouping the aggregate diurnal values. Choose from ["Daily", "Weekly", "Monthly"]. - months : np.ndarray - A list of integers denoting the months to include in the summary - title : str or None - Adds a title to the plot. - unit : str or None - Adds a unit string to the y-axis of the plot. - color : str - A Matplotlib valid color name. An up-to-date list of values is available from https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/colors.py. - tone_color : str or None - Text and border colours throughout the plot. - transparency : bool - Sets transparency of saved plot. - - Returns - ------- - imagePath : str - Path to the saved image - - """ - - # Run input data checks - assert len(annual_values) == 8760, \ - "Number of hourly values passed ({}) does not equal 8760".format(len(annual_values)) - - assert ((min(months) >= 1) & (max(months) <= 12)), \ - "Month integers must be between 1 and 12 (inclusive)" - - # Convert passed values into a pd.Series object (and filter to remove unwanted months) - series = pd.Series(annual_values, index=ANNUAL_DATETIME)[ANNUAL_DATETIME.month.isin(months)] - - if grouping == "Monthly": - assert (len(months) == 12), \ - "Month filtering is not possible when grouping = \"Monthly\"" - - assert os.path.exists(os.path.dirname(save_path)), \ - "\"{}\" does not exist".format(os.path.abspath(os.path.dirname(save_path))) - - # Define grouping methodologies - groupings = { - "Daily": { - "grp": series.index.hour, - "periods": 24, - "xlabels": ["{0:02d}:00".format(i) for i in range(24)], - "xticks": np.arange(0, 24, 1), - "skip_n": [0, 1] - }, - "Weekly": { - "grp": [series.index.dayofweek, series.index.hour], - "periods": 24 * 7, - "xlabels": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], - "xticks": np.arange(0, 24 * 7, 24), - "skip_n": [0, 7] - }, - "Monthly": { - "grp": [series.index.month, series.index.hour], - "periods": 24 * 12, - "xlabels": ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], - "xticks": np.arange(0, 24 * 12, 24), - "skip_n": [0, 12] - } - } - - assert grouping in groupings.keys(), \ - "\"{}\" not available as a filter for grouping annual hourly data. Choose from {}".format(grouping, list(groupings.keys())) - - _grouping = series.groupby(groupings[grouping]["grp"]) - _min = _grouping.min().reset_index(drop=True) - _mean = _grouping.mean().reset_index(drop=True) - _max = _grouping.max().reset_index(drop=True) - # TODO: Add end value to each day/week/month to fill gaps in Series - - # Instantiate plot - fig, ax = plt.subplots(1, 1, figsize=(15, 4)) - - # Plot aggregate - [ax.plot(_mean.iloc[i:i + 24], color=color, lw=2, label='Average') for i in np.arange(0, groupings[grouping]["periods"])[::24]] - [ax.fill_between(np.arange(i, i + 24), _min.iloc[i:i + 24], _max.iloc[i:i + 24], color=color, alpha=0.2, - label='Range') for i in np.arange(0, groupings[grouping]["periods"])[::24]] - ax.set_ylabel(unit, labelpad=2, color=tone_color) - ax.yaxis.set_major_locator(MaxNLocator(7)) - - # Format plot area - [ax.spines[spine].set_visible(False) for spine in ['top', 'right']] - [ax.spines[j].set_color(tone_color) for j in ['bottom', 'left']] - ax.set_xlim([0, groupings[grouping]["periods"]]) - ax.xaxis.set_ticks(groupings[grouping]["xticks"]) - ax.set_xticklabels(groupings[grouping]["xlabels"], ha='left', color=tone_color) - plt.setp(ax.get_yticklabels(), color=tone_color) - ax.grid(b=True, which='major', axis='both', c=tone_color, ls='--', lw=1, alpha=0.3) - ax.tick_params(length=0, labelleft=True, labelright=False, labeltop=False, labelbottom=True, color=tone_color) - - # Legend - handles, labels = ax.get_legend_handles_labels() - lgd = ax.legend(bbox_to_anchor=(0.5, -0.2), loc=8, ncol=3, borderaxespad=0., frameon=False, - handles=[handles[groupings[grouping]["skip_n"][0]], handles[groupings[grouping]["skip_n"][1]]], labels=[labels[groupings[grouping]["skip_n"][0]], labels[groupings[grouping]["skip_n"][1]]]) - lgd.get_frame().set_facecolor((1, 1, 1, 0)) - [plt.setp(text, color=tone_color) for text in lgd.get_texts()] - - # Add a title - if title is None: - plt_title = "{0:} diurnal profile".format(grouping) - else: - plt_title = "{0:}\n{1:} diurnal profile".format(title, grouping) - title = plt.suptitle(plt_title, color=tone_color, ha="left", va="bottom", x=0, y=1.01, transform=ax.transAxes) - - # Tidy plot - plt.tight_layout() - - # Save figure - fig.savefig(save_path, bbox_inches="tight", dpi=300, transparent=False) - - return save_path diff --git a/MachineLearning_Engine/Compute/Charts/Frequency.cs b/MachineLearning_Engine/Compute/Charts/Frequency.cs deleted file mode 100644 index cb09f5d..0000000 --- a/MachineLearning_Engine/Compute/Charts/Frequency.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using System.Collections.Generic; -using BH.oM.Base.Attributes; - -namespace BH.Engine.MachineLearning.Charts -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static string PlotFrequency(List values, string savePath, string title = null, string unit = null, List vRange = null, int bins = 10, string color = "black", string toneColor = "black", bool transparency = false, bool run = false) - { - if (!run) - return null; - - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "Frequency.frequency", values, savePath, title, unit, vRange, bins, color, toneColor, transparency).ToString(); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Charts/Frequency.py b/MachineLearning_Engine/Compute/Charts/Frequency.py deleted file mode 100644 index 7cca303..0000000 --- a/MachineLearning_Engine/Compute/Charts/Frequency.py +++ /dev/null @@ -1,112 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import os -import numpy as np -import pandas as pd -import matplotlib -matplotlib.use("agg") -import matplotlib.pyplot as plt - - -def frequency(values: np.ndarray, save_path: str, title: str=None, unit: str=None, vrange: np.ndarray=None, bins: int=10, color: str="black", tone_color: str="black", transparency=False): - """ Create a histogram with summary table for the data passed - - Parameters - ---------- - values : np.ndarray - List of values to bin. - save_path : str - The full path where the plot will be saved. - title : str or None - Adds a title to the plot. - unit : str or None - Adds a unit string to the x-axis of the histogram. - vrange : np.ndarray or None - Sets the range of values within which the bins will be distributed. - bins : int - Number of bins into which the data should be sorted - color : str - A Matplotlib valid color name. An up-to-date list of values is available from https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/colors.py. - tone_color : str or None - Text and border colours throughout the plot. - transparency : bool - Sets transparency of saved plot. - - Returns - ------- - imagePath : str - Path to the saved image - - """ - - assert os.path.exists(os.path.dirname(save_path)), \ - "\"{}\" does not exist".format(os.path.abspath(os.path.dirname(save_path))) - - # Convert passed values into a pd.Series object - series = pd.Series(values) - - # Instantiate the plot and add sub-plots - fig, ax = plt.subplots(1, 1, figsize=(15, 4)) - - # Plot histogram - if vrange is None: - vrange = [series.min(), series.max()] - ax.hist(series, bins=np.linspace(vrange[0], vrange[1], bins), color=color, alpha=0.9) - - # Format histogram - ax.grid(b=True, which='major', color="k", linestyle=':', alpha=0.5, zorder=3) - [ax.spines[spine].set_visible(False) for spine in ['top', 'right']] - [ax.spines[j].set_color(tone_color) for j in ['bottom', 'left']] - ax.tick_params(length=0, labelleft=True, labelright=False, labeltop=False, labelbottom=True, color=tone_color) - ax.set_ylabel("Hours", color=tone_color) - if vrange is None: - ax.set_xlim(vrange) - if unit is not None: - ax.set_xlabel(unit, color=tone_color) - plt.setp(ax.get_xticklabels(), ha='left', color=tone_color) - plt.setp(ax.get_yticklabels(), color=tone_color) - - if title is not None: - ax.set_title(title, color=tone_color, ha="left", va="bottom", x=0, y=1.01, transform=ax.transAxes) - - # Plot summary statistics - _vals = np.round(series.describe().values, 2) - _ids = ["Count", "Mean", "Std", "Min", "25%", "50%", "75%", "Max"] - summary_text = "" - max_id_length = max([len(i) for i in _ids]) - max_val_length = max([len(str(i)) for i in _vals]) - string_length = max_id_length + max_val_length - for i, j in list(zip(*[_ids, _vals])): - _id_length = len(i) - _val_length = len(str(j)) - space_length = string_length - _id_length - _val_length - summary_text += "{0:}: {1:}{2:}\n".format(i, " " * space_length, j) - txt = ax.text(1.01, 1, summary_text, fontsize=12, color=tone_color, horizontalalignment='left', verticalalignment='top', transform=ax.transAxes, **{'fontname':'Courier New'}) - - # Tidy plot - plt.tight_layout() - - # Save figure - fig.savefig(save_path, bbox_inches="tight", bbox_extra_artists=(txt,), dpi=300, transparent=transparency) - - return save_path diff --git a/MachineLearning_Engine/Compute/Charts/Heatmap.cs b/MachineLearning_Engine/Compute/Charts/Heatmap.cs deleted file mode 100644 index d0b9f44..0000000 --- a/MachineLearning_Engine/Compute/Charts/Heatmap.cs +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using System.Collections.Generic; -using BH.oM.Base.Attributes; - -namespace BH.Engine.MachineLearning.Charts -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static string PlotHeatmap( - List annualValues, - string savePath, - string title = null, - string unit = null, - List vRange = null, - string cmap = "viridis", - string toneColor = "black", - bool invertY = true, - bool transparency = false, - bool run = false - ) - { - if (!run) - return null; - - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, - "Heatmap.heatmap", - annualValues, - savePath, - title, - unit, - vRange, - cmap, - toneColor, - invertY, - transparency - ).ToString(); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Charts/Heatmap.py b/MachineLearning_Engine/Compute/Charts/Heatmap.py deleted file mode 100644 index ef264ea..0000000 --- a/MachineLearning_Engine/Compute/Charts/Heatmap.py +++ /dev/null @@ -1,134 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import os -import numpy as np -import pandas as pd -import matplotlib -matplotlib.use("agg") -import matplotlib.pyplot as plt -from matplotlib.dates import date2num, DateFormatter - -ANNUAL_DATETIME = pd.date_range(start="2018-01-01 00:30:00", freq="60T", periods=8760, closed="left") - - -def heatmap( - annual_values: np.ndarray, - save_path: str, - title: str = None, - unit: str = None, - vrange: np.ndarray = None, - cmap: str = 'viridis', - tone_color: str = "black", - invert_y: bool = False, - transparency: bool = False - ): - """ Generate a heatmap from a set of annual hourly values - - Parameters - ---------- - annual_values : np.ndarray - List of 8760 annual hourly values. - save_path : str - The full path where the plot will be saved. - title : str or None - Adds a title to the plot. - unit : str or None - Adds a unit string to the color-bar associated with the heatmap. - vrange : np.ndarray or None - Sets the range of values within which the color-bar will be applied. - cmap : str or None - A Matplotlib valid colormap name. An up-to-date list of values is available from https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/_color_data.py. - tone_color : str or None - Text and border colours throughout the plot. - invert_y : bool - Reverse the y-axis so that 0-24 hours runs from top to bottom. - transparency : bool - Sets transparency of saved plot. - - Returns - ------- - imagePath : str - Path to the saved image - """ - - # Run input data checks - assert len(annual_values) == 8760, \ - "Number of hourly values passed ({}) does not equal 8760".format(len(annual_values)) - - assert os.path.exists(os.path.dirname(save_path)), \ - "\"{}\" does not exist".format(os.path.abspath(os.path.dirname(save_path))) - - # Create DataFrame from passed values - df = pd.DataFrame(data=annual_values, index=ANNUAL_DATETIME, columns=[title]) - - # Reshape data into time/day matrix - annual_matrix = df.pivot_table(columns=df.index.date, index=df.index.time).values[::-1] - - # Instantiate figure - fig, ax = plt.subplots(1, 1, figsize=(15, 5)) - - # Plot data - heatmap = ax.imshow( - annual_matrix, - extent=[date2num(df.index.min()), date2num(df.index.max()), 726449, 726450], - aspect='auto', - cmap=cmap, - interpolation='none', - vmin=vrange[0] if vrange is not None else None, - vmax=vrange[-1] if vrange is not None else None, - ) - - # Axis formatting - ax.xaxis_date() - ax.xaxis.set_major_formatter(DateFormatter('%b')) - ax.yaxis_date() - ax.yaxis.set_major_formatter(DateFormatter('%H:%M')) - if invert_y: - ax.invert_yaxis() - ax.tick_params(labelleft=True, labelright=True, labelbottom=True, color=tone_color) - plt.setp(ax.get_xticklabels(), ha='left', color=tone_color) - plt.setp(ax.get_yticklabels(), color=tone_color) - - # Spine formatting - [ax.spines[spine].set_visible(False) for spine in ['top', 'bottom', 'left', 'right']] - - # Grid formatting - ax.grid(b=True, which='major', color='white', linestyle=':', alpha=1) - - # Color-bar formatting - cb = fig.colorbar(heatmap, orientation='horizontal', drawedges=False, fraction=0.05, aspect=100, pad=0.075) - plt.setp(plt.getp(cb.ax.axes, 'xticklabels'), color=tone_color) - cb.set_label(unit, color=tone_color) - cb.outline.set_visible(False) - - # Add title if provided - if title is not None: - plt.title(title, color=tone_color, ha="left", va="bottom", x=0, y=1.01, transform=ax.transAxes) - - # Tidy plot - plt.tight_layout() - - # Save figure - fig.savefig(save_path, bbox_inches="tight", dpi=300, transparent=transparency) - - return save_path diff --git a/MachineLearning_Engine/Compute/Charts/PlotImage.cs b/MachineLearning_Engine/Compute/Charts/PlotImage.cs deleted file mode 100644 index c89321c..0000000 --- a/MachineLearning_Engine/Compute/Charts/PlotImage.cs +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using BH.oM.MachineLearning.Vision; - -namespace BH.Engine.MachineLearning.Charts -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static object PlotImage(Image image, int height, int width, bool grayscale = false) - { - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "PlotImage.plot_pil_image", image, height, width, grayscale); - } - - /*************************************/ - - public static object PlotImage(Tensor tensor, int height, int width, bool grayscale = false) - { - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "PlotImage.plot_tensor_image", tensor, height, width, grayscale); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Charts/PlotImage.py b/MachineLearning_Engine/Compute/Charts/PlotImage.py deleted file mode 100644 index 096688a..0000000 --- a/MachineLearning_Engine/Compute/Charts/PlotImage.py +++ /dev/null @@ -1,59 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import PIL -import torch -import torchvision -import matplotlib.pyplot as plt -import os -import subprocess - - -def plot_pil_image(image: PIL.Image, height: int, width: int, grayscale: bool): - fig = plt.figure(figsize=(height, width)) - - if grayscale: - cmap = "gray" - else: - cmap = None - - plt.imshow(image, cmap=cmap) - plt.tight_layout() - - home = os.path.abspath("C:\\ProgramData\\BHoM\\Extensions\\Python\\temp\\") - if not os.path.exists(home): - os.makedirs(home, exist_ok=True) - - path = os.path.join(home, "current_plot.png") - if os.path.exists(path): - os.remove(path) - - plt.savefig(path) - - subprocess.run(["explorer", path]) - return - - -def plot_tensor_image(image: torch.Tensor, height: int, width: int, grayscale: bool): - image = image.float() - pil_image = torchvision.transforms.functional.to_pil_image(image.cpu()) - return plot_pil_image(pil_image, height, width, grayscale) diff --git a/MachineLearning_Engine/Compute/Charts/UTCI.cs b/MachineLearning_Engine/Compute/Charts/UTCI.cs deleted file mode 100644 index 12439b6..0000000 --- a/MachineLearning_Engine/Compute/Charts/UTCI.cs +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using System.Collections.Generic; -using BH.oM.Base.Attributes; - -namespace BH.Engine.MachineLearning.Charts -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static string PlotUTCI( - List annualValues, - string savePath, - bool detailed = false, - string title = "", - string toneColor = "black", - bool invertY = true, - bool transparency = false, - bool run = false - ) - { - if (!run) - return null; - - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, - "UTCI.utci", - annualValues, - savePath, - detailed, - title, - toneColor, - invertY, - transparency - ).ToString(); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Charts/UTCI.py b/MachineLearning_Engine/Compute/Charts/UTCI.py deleted file mode 100644 index a9d54bc..0000000 --- a/MachineLearning_Engine/Compute/Charts/UTCI.py +++ /dev/null @@ -1,272 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import os -import numpy as np -import pandas as pd -import matplotlib -matplotlib.use("agg") -import matplotlib.pyplot as plt -from matplotlib.colors import ListedColormap, BoundaryNorm -from matplotlib.dates import date2num, DateFormatter - -ANNUAL_DATETIME = pd.date_range(start="2018-01-01 00:30:00", freq="60T", periods=8760, closed="left") - - -def utci( - annual_values: np.ndarray, - save_path: str, - detailed: bool = False, - title: str = None, - tone_color: str = "black", - invert_y: bool = False, - transparency: bool = False - ): - """ Generate a UTCI heatmap from a set of annual hourly values - - Parameters - ---------- - annual_values : np.ndarray - List of 8760 annual hourly values. - save_path : str - The full path where the plot will be saved. - detailed : bool - Set to True to include monthly stacked charts with proportion of time comfortable. - title : str or None - Adds a title to the plot. - tone_color : str or None - Text and border colours throughout the plot. - invert_y : bool - Reverse the y-axis so that 0-24 hours runs from top to bottom. - transparency : bool - Sets transparency of saved plot. - - Returns - ------- - imagePath : str - Path to the saved image - """ - - # Run input data checks - assert len(annual_values) == 8760, \ - "Number of hourly values passed ({}) does not equal 8760".format(len(annual_values)) - - assert os.path.exists(os.path.dirname(save_path)), \ - "\"{}\" does not exist".format(os.path.abspath(os.path.dirname(save_path))) - - # Create DataFrame from passed values - df = pd.DataFrame(data=annual_values, index=ANNUAL_DATETIME, columns=[title]) - - # Reshape data into time/day matrix for heatmap plotting - annual_matrix = df.pivot_table(columns=df.index.date, index=df.index.time).values[::-1] - - # Create UTCI colormap - utci_cmap = ListedColormap(['#0D104B', '#262972', '#3452A4', '#3C65AF', '#37BCED', '#2EB349', '#F38322', '#C31F25', '#7F1416', '#580002']) - utci_cmap_bounds = [-100, -40, -27, -13, 0, 9, 26, 32, 38, 46, 100] - utci_cmap_norm = BoundaryNorm(utci_cmap_bounds, utci_cmap.N) - - bounds = np.arange(-41, 48, 1) - norm = BoundaryNorm(bounds, max(len(bounds), utci_cmap.N)) - - if not detailed: - # Instantiate figure - fig, ax = plt.subplots(1, 1, figsize=(15, 5)) - - # Plot data - heatmap = ax.imshow( - annual_matrix, - extent=[date2num(df.index.min()), date2num(df.index.max()), 726449, 726450], - aspect='auto', - cmap=utci_cmap, - interpolation='none', - vmin=-40, - vmax=46, - norm=utci_cmap_norm - ) - - # Axis formatting - ax.xaxis_date() - ax.xaxis.set_major_formatter(DateFormatter('%b')) - ax.yaxis_date() - ax.yaxis.set_major_formatter(DateFormatter('%H:%M')) - if invert_y: - ax.invert_yaxis() - ax.tick_params(length=0, labelleft=True, labelright=True, labeltop=False, labelbottom=True, color=tone_color) - plt.setp(ax.get_xticklabels(), ha='left', color=tone_color) - plt.setp(ax.get_yticklabels(), color=tone_color) - - # Spine formatting - [ax.spines[spine].set_visible(False) for spine in ['top', 'bottom', 'left', 'right']] - - # Grid formatting - ax.grid(b=True, which='major', color='white', linestyle=':', alpha=1) - - # Add colorbar legend and text descriptors for comfort bands - # cb = fig.colorbar(heatmap, orientation='horizontal', drawedges=False, fraction=0.05, aspect=100, pad=0.075) - cb = fig.colorbar(heatmap, cmap=utci_cmap, norm=norm, boundaries=bounds, orientation='horizontal', drawedges=False, fraction=0.05, aspect=100, pad=0.15, extend='both', ticks=[-40, -27, -13, 0, 9, 26, 32, 38, 46]) - plt.setp(plt.getp(cb.ax.axes, 'xticklabels'), color=tone_color) - cb.set_label("°C", color=tone_color) - cb.outline.set_visible(False) - y_move = -0.135 - ax.text(0, y_move, 'Extreme\ncold stress', ha='center', va='center', transform=ax.transAxes, color=tone_color, fontsize='small') - ax.text(np.interp(-27 + (-40 - -27) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Very strong\ncold stress', ha='center', va='center', transform=ax.transAxes, color=tone_color, fontsize='small') - ax.text(np.interp(-13 + (-27 - -13) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Strong\ncold stress', ha='center', va='center', transform=ax.transAxes, color=tone_color, fontsize='small') - ax.text(np.interp(0 + (-13 - 0) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Moderate\ncold stress', ha='center', va='center', transform=ax.transAxes, color=tone_color, fontsize='small') - ax.text(np.interp(0 + (9 - 0) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Slight\ncold stress', ha='center', va='center', transform=ax.transAxes, color=tone_color, fontsize='small') - ax.text(np.interp(9 + (26 - 9) / 2, [-44.319, 50.319], [0, 1]), y_move, 'No thermal stress', ha='center', va='center', transform=ax.transAxes, color=tone_color, fontsize='small') - ax.text(np.interp(26 + (32 - 26) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Moderate\nheat stress', ha='center', va='center', transform=ax.transAxes, color=tone_color, fontsize='small') - ax.text(np.interp(32 + (38 - 32) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Strong\nheat stress', ha='center', va='center', transform=ax.transAxes, color=tone_color, fontsize='small') - ax.text(np.interp(38 + (46 - 38) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Very strong\nheat stress', ha='center', va='center', transform=ax.transAxes, color=tone_color, fontsize='small') - ax.text(1, y_move, 'Extreme\nheat stress', ha='center', va='center', transform=ax.transAxes, color=tone_color, fontsize='small') - - # Add title if provided - if title is None: - plt_title = "Universal Thermal Climate Index" - else: - plt_title = "{0:}\nUniversal Thermal Climate Index".format(title) - ti = plt.title(plt_title, color=tone_color, ha="left", va="bottom", x=0, y=1.01, transform=ax.transAxes) - - else: - fig = plt.figure(figsize=(15, 6), constrained_layout=True) - spec = fig.add_gridspec(ncols=1, nrows=2, width_ratios=[1], height_ratios=[2, 1], hspace=0.1) - - hmap = fig.add_subplot(spec[0, 0]) - hbar = fig.add_subplot(spec[1, 0]) - - # Plot heatmap - heatmap = hmap.imshow(pd.pivot_table(df, index=df.index.time, columns=df.index.date, - values=df.columns[0]).values[::-1], norm=utci_cmap_norm, - extent=[date2num(df.index.min()), date2num(df.index.max()), 726449, - 726450], - aspect='auto', cmap=utci_cmap, interpolation='none', vmin=-40, vmax=46) - hmap.xaxis_date() - hmap.xaxis.set_major_formatter(DateFormatter('%b')) - hmap.yaxis_date() - hmap.yaxis.set_major_formatter(DateFormatter('%H:%M')) - if invert_y: - hmap.invert_yaxis() - hmap.tick_params(length=0, labelleft=True, labelright=True, labeltop=False, labelbottom=True, color=tone_color) - plt.setp(hmap.get_xticklabels(), ha='left', color=tone_color) - plt.setp(hmap.get_yticklabels(), color=tone_color) - for spine in ['top', 'bottom', 'left', 'right']: - hmap.spines[spine].set_visible(False) - hmap.spines[spine].set_color(tone_color) - hmap.grid(b=True, which='major', color="white", linestyle=':', alpha=1) - - # Add colorbar legend and text descriptors for comfort bands - cb = fig.colorbar(heatmap, cmap=utci_cmap, norm=norm, boundaries=bounds, - orientation='horizontal', drawedges=False, fraction=0.01, aspect=50, - pad=-0.0, extend='both', ticks=[-40, -27, -13, 0, 9, 26, 32, 38, 46]) - plt.setp(plt.getp(cb.ax.axes, 'xticklabels'), color=tone_color) - cb.outline.set_visible(False) - cb.set_label("°C", color=tone_color) - - y_move = -0.4 - hbar.text(0, y_move, 'Extreme\ncold stress', ha='center', va='center', transform=hbar.transAxes, - color=tone_color, - fontsize='small') - hbar.text(np.interp(-27 + (-40 - -27) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Very strong\ncold stress', - ha='center', va='center', transform=hbar.transAxes, color=tone_color, fontsize='small') - hbar.text(np.interp(-13 + (-27 - -13) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Strong\ncold stress', - ha='center', - va='center', transform=hbar.transAxes, color=tone_color, fontsize='small') - hbar.text(np.interp(0 + (-13 - 0) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Moderate\ncold stress', ha='center', - va='center', transform=hbar.transAxes, color=tone_color, fontsize='small') - hbar.text(np.interp(0 + (9 - 0) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Slight\ncold stress', ha='center', - va='center', transform=hbar.transAxes, color=tone_color, fontsize='small') - hbar.text(np.interp(9 + (26 - 9) / 2, [-44.319, 50.319], [0, 1]), y_move, 'No thermal stress', ha='center', - va='center', transform=hbar.transAxes, color=tone_color, fontsize='small') - hbar.text(np.interp(26 + (32 - 26) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Moderate\nheat stress', - ha='center', - va='center', transform=hbar.transAxes, color=tone_color, fontsize='small') - hbar.text(np.interp(32 + (38 - 32) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Strong\nheat stress', ha='center', - va='center', transform=hbar.transAxes, color=tone_color, fontsize='small') - hbar.text(np.interp(38 + (46 - 38) / 2, [-44.319, 50.319], [0, 1]), y_move, 'Very strong\nheat stress', - ha='center', - va='center', transform=hbar.transAxes, color=tone_color, fontsize='small') - hbar.text(1, y_move, 'Extreme\nheat stress', ha='center', va='center', transform=hbar.transAxes, - color=tone_color, - fontsize='small') - - # Add stacked plot - bins = [-100, -40, -27, -13, 0, 9, 26, 32, 38, 46, 100] - tags = ["Extreme cold stress", "Very strong cold stress", "Strong cold stress", "Moderate cold stress", - "Slight cold stress", "No thermal stress", "Moderate heat stress", "Strong heat stress", - "Very strong heat stress", "Extreme heat stress"] - months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] - - clrs = utci_cmap.colors - - adf = pd.DataFrame() - for mnth_n, mnth in enumerate(months): - # Filter the series to return only the month - a = df[df.index.month == mnth_n + 1].dropna().values - a = pd.Series(index=tags, name=mnth, - data=[((a > i) & (a <= j)).sum() / len(a) for n, (i, j) in - enumerate(zip(bins[:-1], bins[1:]))]) - adf = pd.concat([adf, a], axis=1) - adf = adf.T[tags] - adf.plot(kind="bar", ax=hbar, stacked=True, color=clrs, width=1, legend=False) - hbar.set_xlim(-0.5, 11.5) - # - # # Major ticks - hbar.set_xticks(np.arange(-0.5, 11, 1)) - - # Labels for major ticks - hbar.set_xticklabels(months) - - plt.setp(hbar.get_xticklabels(), ha='center', rotation=0, color=tone_color) - plt.setp(hbar.get_xticklabels(), ha='left', color=tone_color) - plt.setp(hbar.get_yticklabels(), color=tone_color) - for spine in ['top', 'right']: - hbar.spines[spine].set_visible(False) - for spine in ['bottom', 'left']: - hbar.spines[spine].set_color(tone_color) - hbar.grid(b=True, which='major', color="white", linestyle=':', alpha=1) - hbar.set_yticklabels(['{:,.0%}'.format(x) for x in hbar.get_yticks()]) - - # Add header percentages for bar plot - cold_percentages = adf.iloc[:, :5].sum(axis=1).values - comfortable_percentages = adf.iloc[:, 5] - hot_percentages = adf.iloc[:, 6:].sum(axis=1).values - for n, (i, j, k) in enumerate(zip(*[cold_percentages, comfortable_percentages, hot_percentages])): - hbar.text(n, 1.02, "{0:0.1f}%".format(i * 100), va="bottom", ha="center", color="#3C65AF", fontsize="small") - hbar.text(n, 1.02, "{0:0.1f}%\n".format(j * 100), va="bottom", ha="center", color="#2EB349", - fontsize="small") - hbar.text(n, 1.02, "{0:0.1f}%\n\n".format(k * 100), va="bottom", ha="center", color="#C31F25", - fontsize="small") - hbar.set_ylim(0, 1) - - # Add title if provided - if title is None: - plt_title = "Universal Thermal Climate Index" - else: - plt_title = "{0:}\nUniversal Thermal Climate Index".format(title) - ti = hmap.set_title(plt_title, color=tone_color, ha="left", va="bottom", x=0, y=1.01, transform=hmap.transAxes) - - # Tidy figure - plt.tight_layout() - - # Save figure - fig.savefig(save_path, bbox_inches="tight", bbox_extra_artists=[ti,], dpi=300, transparent=transparency) - - return save_path diff --git a/MachineLearning_Engine/Compute/Charts/__init__.py b/MachineLearning_Engine/Compute/Charts/__init__.py deleted file mode 100644 index ec85768..0000000 --- a/MachineLearning_Engine/Compute/Charts/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from . import Diurnal -from . import UTCI -from . import Frequency -from . import Heatmap -from . import PlotImage \ No newline at end of file diff --git a/MachineLearning_Engine/Compute/Datasets/LoadCsv.cs b/MachineLearning_Engine/Compute/Datasets/LoadCsv.cs deleted file mode 100644 index 4db9d1b..0000000 --- a/MachineLearning_Engine/Compute/Datasets/LoadCsv.cs +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.Engine.MachineLearning; -using BH.oM.MachineLearning; -using BH.oM.Base; -using BH.oM.Base.Attributes; -using System; -using System.IO; -using System.Linq; -using System.Collections.Generic; -using System.ComponentModel; - -namespace BH.Engine.MachineLearning.Datasets -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Reads a csv file and loads it into a Tensor primitive.")] - [Input("path", "The path to the csv file. If using a relative path, the root will be C:/ProgramData/BHoM")] - [Input("separator", "The separator character of the csv, e,g, a tsv. Use \\t for tabs.")] - [Input("hasHeaders", "True if the first line of the csv is a headers line, false otherwise.")] - [MultiOutput(0, "headers", "A list of headers as string if headers are present in the csv. An empty list otherswise.")] - [MultiOutput(1, "tensor", "A 2D tensor with dimensions (numberOfRow, numberOfColumns)")] - public static Output, Tensor> LoadCsv(string path, string separator = ",", bool hasHeaders = true) - { - if (!Path.IsPathRooted(path)) - path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "BHoM", path); - - List headers = new List(); - if (!File.Exists(path)) - { - Engine.Base.Compute.RecordError((new FileNotFoundException("", path)).Message); - return Engine.Base.Create.Output, Tensor>(headers, null); - } - - char sep = separator.ToCharArray().First(); - using (StreamReader reader = new StreamReader(path)) - { - List matrix = new List(); - // strip headers - if (hasHeaders) - headers = reader.ReadLine().Split(sep).ToList(); - - while (!reader.EndOfStream) - { - string line = reader.ReadLine(); - string[] values = line.Split(sep); - matrix.Add(values); - } - return Engine.Base.Create.Output(headers, Create.Tensor(matrix)); - } - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/InstallMachineLearningToolkit.cs b/MachineLearning_Engine/Compute/InstallMachineLearningToolkit.cs deleted file mode 100644 index 2bb7705..0000000 --- a/MachineLearning_Engine/Compute/InstallMachineLearningToolkit.cs +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using BH.oM.Base.Attributes; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; - -namespace BH.Engine.MachineLearning.Base -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Install the python bindings of the Machine Learning Toolkit. This includes standard machine learning packages \n" + - "as the BHoM methods developed in python. Note that this depends on the Python_Toolkit.")] - [Input("run", "Starts the installation of the toolkit if true. Stays idle otherwise.")] - [Input("force", "If the toolkit is already installed it forces a reinstall of all the packages. It does not force a reinstall of Python.")] - [MultiOutput(0, "success", "True if installation is successful, false otherwise.")] - [MultiOutput(1, "packages", "The list of succesfully installed packages")] - public static Output> InstallMachineLearningToolkit(bool run = false, bool force = false) - { - bool success = false; - List installedPackages = new List(); - - if (!run) - return new Output> { Item1 = success, Item2 = installedPackages }; - - // install the python toolkit if necessary - if (!BH.Engine.Python.Query.IsPythonInstalled()) - BH.Engine.Python.Compute.InstallPythonToolkit(run, force); - - // the requirements.txt file is copied to the python home in the postbuil events - we only pick it up now at runtime to install the toolkit lazily - string requirementsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "BHoM", "Extensions", "Python", "src", "requirements.txt"); - - // install from requirements.txt file - Console.WriteLine("Installing requiremented packages..."); - Python.Compute.PipInstall($"-r {requirementsPath} -f https://download.pytorch.org/whl/torch_stable.html"); - - // check if installed correctly - string[] packages = File.ReadAllLines(requirementsPath); - installedPackages = packages.Where(x => Python.Query.IsModuleInstalled(x)).ToList(); - - // install pyBHoM - Console.WriteLine("Installing MachineLearning_Toolkit..."); - string module = "MachineLearning_Toolkit"; - string mlPath = Path.Combine(Python.Query.EmbeddedPythonHome(), "src", module); - Engine.Python.Compute.PipInstall($"-e {mlPath}", force: force); - if (Python.Query.IsModuleInstalled(module)) - installedPackages.Add(module); - - success = true; - return new Output>() { Item1 = success, Item2 = installedPackages }; - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Vision/RecogniseObject.cs b/MachineLearning_Engine/Compute/InstallPythonEnv_ML.cs similarity index 63% rename from MachineLearning_Engine/Compute/Vision/RecogniseObject.cs rename to MachineLearning_Engine/Compute/InstallPythonEnv_ML.cs index 850732b..9a894d6 100644 --- a/MachineLearning_Engine/Compute/Vision/RecogniseObject.cs +++ b/MachineLearning_Engine/Compute/InstallPythonEnv_ML.cs @@ -20,28 +20,28 @@ * along with this code. If not, see . */ -using BH.oM.Base.Attributes; + +using BH.oM.Python; using System.ComponentModel; -namespace BH.Engine.MachineLearning.Vision +using BH.oM.Base.Attributes; + +namespace BH.Engine.MachineLearning { public static partial class Compute { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Returns the type of object in the image, e.g. an apple")] - [Input("Image path", "The absolute path to the image to analyse")] - [Input("Gpu", "If true, computation is accelarated using a capable gpu")] - [Output("Object", "The probabilities (score) for each class. Use the Query.ImageClasses() method to match ")] - public static string RecogniseObject(string imagePath, bool gpu = false) + [Description("MachineLearning_Toolkit\nMethod used to create the Python environment used to run all Python scripts within this toolkit.")] + [Input("run", "Starts the installation of the toolkit if true. Stays idle otherwise.")] + [Output("pythonEnvironment", "The MachineLearning_Toolkit Python environment.")] + [PreviousVersion("5.3", "BH.Engine.MachineLearning.Base.Compute.InstallMachineLearningToolkit(System.Boolean, System.Boolean)")] + public static PythonEnvironment InstallPythonEnv_ML(bool run = false) { - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "RecogniseObject.infer", imagePath, gpu).As(); + return BH.Engine.Python.Compute.InstallVirtualenv( + name: Query.ToolkitName(), + BH.oM.Python.Enums.PythonVersion.v3_7_9, + localPackage: $@"C:\ProgramData\BHoM\Extensions\PythonCode\{Query.ToolkitName()}", + run: run + ); } - - /*************************************/ } } - - diff --git a/MachineLearning_Engine/Compute/Invoke.cs b/MachineLearning_Engine/Compute/Invoke.cs deleted file mode 100644 index d7d9d37..0000000 --- a/MachineLearning_Engine/Compute/Invoke.cs +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using Python.Runtime; -using System.Collections.Generic; -using System.Linq; - -namespace BH.Engine.MachineLearning.Base -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static PyObject Invoke(string nameSpace, string method, params object[] args) - { - PyObject mlComputeModule = Query.Import("MachineLearning_Engine.Compute." + nameSpace.Split('.').Last()); - - PyObject[] pyargs = new PyObject[args.Length]; - for (int i = 0; i < args.Length; i++) - pyargs[i] = Engine.MachineLearning.Convert.IToPython(args[i]); - - return Python.Compute.Invoke(mlComputeModule, method, pyargs, null); - } - - /*************************************/ - - public static PyObject Invoke(string nameSpace, string method, Dictionary kwargs) - { - PyObject mlComputeModule = Query.Import("MachineLearning_Engine.Compute." + nameSpace.Split('.').Last()); - return BH.Engine.Python.Compute.Invoke(mlComputeModule, method, null, kwargs); - } - - /***************************************************/ - - public static PyObject InvokeNumpy(string method, IEnumerable args = null, Dictionary kwargs = null) - { - PyObject numpyModule = Query.Import("numpy"); - return BH.Engine.Python.Compute.Invoke(numpyModule, method, args, kwargs); - } - - /***************************************************/ - - public static PyObject InvokeNumpy(string method, params object[] args) - { - PyObject numpyModule = Query.Import("numpy"); - return BH.Engine.Python.Compute.Invoke(numpyModule, method, args, null); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Preprocessing/MinMaxScaler.cs b/MachineLearning_Engine/Compute/Preprocessing/MinMaxScaler.cs deleted file mode 100644 index feeb454..0000000 --- a/MachineLearning_Engine/Compute/Preprocessing/MinMaxScaler.cs +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using BH.oM.Base.Attributes; -using Python.Runtime; -using System.ComponentModel; - -namespace BH.Engine.MachineLearning.Preprocessing -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Rescale the data to a given range between 0 and 1.")] - [Input("x", "Data to be rescaled.")] - [Output("scaler", "The estimated scaler for the min-max scale transformation.")] - public static MinMaxScaler MinMaxScaler(Tensor x) - { - PyObject scaler = BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "MinMaxScaler.fit", x); - return new MinMaxScaler(scaler); - } - - /*************************************/ - - [Description("Rescale the data with a given min-max scaler.")] - [Input("scaler", "The given scaler for the min-max scale transformation.")] - [Input("x", "Data to be rescaled.")] - [Output("rescaledX", "The rescaled data with a range between o and 1.")] - public static Tensor Infer(MinMaxScaler scaler, Tensor x) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "MinMaxScaler.infer", scaler, x)); - } - - /*************************************/ - [Description("Inverse transformation of data with the given scaler.")] - [Input("scaler", "The min-max scaler used for inverse transformation.")] - [Input("x", "Data to be inverse-transformed.")] - [Output("inversedX", "The inverse transformed data using the min-max scaler.")] - public static Tensor InferInverse(MinMaxScaler scaler, Tensor x) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "MinMaxScaler.infer_inverse", scaler, x)); - } - - /*************************************/ - - } -} - - diff --git a/MachineLearning_Engine/Compute/Preprocessing/MinMaxScaler.py b/MachineLearning_Engine/Compute/Preprocessing/MinMaxScaler.py deleted file mode 100644 index dc0b441..0000000 --- a/MachineLearning_Engine/Compute/Preprocessing/MinMaxScaler.py +++ /dev/null @@ -1,46 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from sklearn.preprocessing import MinMaxScaler -import numpy as np - - -def fit(x: np.ndarray): - # instantiace a min-max scaler - scaler = MinMaxScaler() - - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - return scaler.fit(x) - -def infer(scaler: MinMaxScaler, x: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - return scaler.transform(x) - -def infer_inverse(scaler: MinMaxScaler, x: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - return scaler.inverse_transform(x) \ No newline at end of file diff --git a/MachineLearning_Engine/Compute/Preprocessing/PolynomialFeatures.cs b/MachineLearning_Engine/Compute/Preprocessing/PolynomialFeatures.cs deleted file mode 100644 index 2eb5288..0000000 --- a/MachineLearning_Engine/Compute/Preprocessing/PolynomialFeatures.cs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using BH.oM.Base.Attributes; -using Python.Runtime; -using System.ComponentModel; - -namespace BH.Engine.MachineLearning.Preprocessing -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Create a trnasformer for polynomial and interaction features of the data.")] - [Input("degree", "The degree of the polynomial features. Default as 2.")] - [Input("interactionOnly", "The option to generate only interaction features. Default as false.")] - [Output("transformer", "The transformer for the polynomial and interaction features of the data.")] - public static PolynomialFeatures PolynomialFeatures(int degree = 2, bool interaction_only = false) - { - PyObject transformer = BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "PolynomialFeatures.fit", degree, interaction_only); - return new PolynomialFeatures(transformer); - } - - /*************************************/ - - [Description("Generate polynomial and interaction features of the data.")] - [Input("transformer", "The transformer for the polynomial and interaction features of the given data.")] - [Input("x", "Data to be transformed.")] - [Output("transformedX", "The polynomial and interaction features of the data.")] - public static Tensor Infer(PolynomialFeatures transformer, Tensor x) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "PolynomialFeatures.infer", transformer, x)); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Preprocessing/PolynomialFeatures.py b/MachineLearning_Engine/Compute/Preprocessing/PolynomialFeatures.py deleted file mode 100644 index 678db99..0000000 --- a/MachineLearning_Engine/Compute/Preprocessing/PolynomialFeatures.py +++ /dev/null @@ -1,38 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from sklearn.preprocessing import PolynomialFeatures -import numpy as np - - -def fit(deg: int, interaction: bool): - # instantiace a polynomial features transformer - transformer = PolynomialFeatures(degree = deg, interaction_only = interaction) - - return transformer - -def infer(transformer: PolynomialFeatures, x: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - - return transformer.fit_transform(x) \ No newline at end of file diff --git a/MachineLearning_Engine/Compute/Preprocessing/StandardScaler.cs b/MachineLearning_Engine/Compute/Preprocessing/StandardScaler.cs deleted file mode 100644 index 87f979e..0000000 --- a/MachineLearning_Engine/Compute/Preprocessing/StandardScaler.cs +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using BH.oM.Base.Attributes; -using Python.Runtime; -using System.ComponentModel; - -namespace BH.Engine.MachineLearning.Preprocessing -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Rescale the data with standard scaler.")] - [Input("x", "Data to be rescaled.")] - [Output("scaler", "The estimated scaler for the standard scale transformation.")] - public static StandardScaler StandardScaler(Tensor x) - { - PyObject scaler = BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "StandardScaler.fit", x); - return new StandardScaler(scaler); - } - - /*************************************/ - - [Description("Rescale the data with a given standard scaler.")] - [Input("scaler", "The given scaler for the standard scale transformation.")] - [Input("x", "Data to be rescaled.")] - [Output("rescaledX", "The rescaled data after the given standard scale transformation.")] - public static Tensor Infer(StandardScaler scaler, Tensor x) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "StandardScaler.infer", scaler, x)); - } - - /*************************************/ - [Description("Inverse transformation of data with the given scaler.")] - [Input("scaler", "The standard scaler used for inverse transformation.")] - [Input("x", "Data to be inverse-transformed.")] - [Output("inversedX", "The inverse transformed data using the standard scaler.")] - public static Tensor InferInverse(StandardScaler scaler, Tensor x) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "StandardScaler.infer_inverse", scaler, x)); - } - - /*************************************/ - - } -} - - diff --git a/MachineLearning_Engine/Compute/Preprocessing/StandardScaler.py b/MachineLearning_Engine/Compute/Preprocessing/StandardScaler.py deleted file mode 100644 index 3440f33..0000000 --- a/MachineLearning_Engine/Compute/Preprocessing/StandardScaler.py +++ /dev/null @@ -1,46 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from sklearn.preprocessing import StandardScaler -import numpy as np - - -def fit(x: np.ndarray): - # instantiace a min-max scaler - scaler = StandardScaler() - - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - return scaler.fit(x) - -def infer(scaler: StandardScaler, x: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - return scaler.transform(x) - -def infer_inverse(scaler: StandardScaler, x: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - return scaler.inverse_transform(x) \ No newline at end of file diff --git a/MachineLearning_Engine/Compute/Preprocessing/__init__.py b/MachineLearning_Engine/Compute/Preprocessing/__init__.py deleted file mode 100644 index ef40907..0000000 --- a/MachineLearning_Engine/Compute/Preprocessing/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from . import MinMaxScaler -from . import PolynomialFeatures -from . import StandardScaler diff --git a/MachineLearning_Engine/Compute/Structured/Coefficients.cs b/MachineLearning_Engine/Compute/Structured/Coefficients.cs deleted file mode 100644 index 3887934..0000000 --- a/MachineLearning_Engine/Compute/Structured/Coefficients.cs +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using BH.oM.Base; -using BH.oM.Base.Attributes; -using BH.Engine.MachineLearning; -using System; -using System.Linq; -using System.Collections.Generic; -using System.ComponentModel; - -namespace BH.Engine.MachineLearning.Structured -{ - public static partial class Compute - { - /*************************************/ - /**** Public Fields ****/ - /*************************************/ - - [Description("Expose the attributes for the given regression model.")] - [Input("model", "The regression model used for inference.")] - [MultiOutput(0, "coefficients", "Estimated coefficients for the regression model. This is a 1D array of double.")] - [MultiOutput(1, "intercept", "The independent term in the model.")] - public static Output Coefficients(IRegressionModel model) - { - Tensor coefficients = new Tensor(model.SkLearnModel.GetAttr("coef_")); - Tensor intercept = new Tensor(model.SkLearnModel.GetAttr("intercept_")); - return new Output { Item1 = coefficients, Item2 = intercept }; - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Structured/LinearRegression.cs b/MachineLearning_Engine/Compute/Structured/LinearRegression.cs deleted file mode 100644 index a0215b1..0000000 --- a/MachineLearning_Engine/Compute/Structured/LinearRegression.cs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.Engine.MachineLearning; -using BH.oM.MachineLearning; -using BH.oM.Base; -using BH.oM.Base.Attributes; -using Python.Runtime; -using System; -using System.Linq; -using System.Collections.Generic; -using System.ComponentModel; - -namespace BH.Engine.MachineLearning.Structured -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Finds the slope and the intercept of a linear function that best fits the given set of bidimensional data.")] - [Input("x", "Training data as a list of 2-elements list.")] - [Input("y", "Target values as a list of 2-elements list.")] - [Output("model", "The ordinary least squares linear regression with the given data.")] - public static LinearRegression LinearRegression(Tensor x, Tensor y) - { - PyObject model = BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "LinearRegression.fit", x, y); - return new LinearRegression(model); - } - - /*************************************/ - - [Description("Projects the given input using a linear regression model.")] - [Input("model", "The linear regressor model used for inference.")] - [Input("x", "Data to project on.")] - [Output("y", "The projected output for the given data using the linear model.")] - public static Tensor Infer(LinearRegression model, Tensor x) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "LinearRegression.infer", model, x)); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Structured/LinearRegression.py b/MachineLearning_Engine/Compute/Structured/LinearRegression.py deleted file mode 100644 index 2907804..0000000 --- a/MachineLearning_Engine/Compute/Structured/LinearRegression.py +++ /dev/null @@ -1,56 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from sklearn.linear_model import LinearRegression -import numpy as np - - -def fit(x: np.ndarray, y: np.ndarray): - assert len(x) == len(y), "Input data and target data have different length {} and {}".format( - len(x), len(y)) - - # instantiace linear regression model - model = LinearRegression() - - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - if y.ndim == 1: - y = y.reshape(-1, 1) - - # fit the training data - model.fit(x, y) - return model - -def infer(model: LinearRegression, x: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - return model.predict(x) - -def score(model: LinearRegression, x: np.ndarray, y: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - if y.ndim == 1: - y = y.reshape(-1, 1) - return model.score(x, y) \ No newline at end of file diff --git a/MachineLearning_Engine/Compute/Structured/LogisticRegression.cs b/MachineLearning_Engine/Compute/Structured/LogisticRegression.cs deleted file mode 100644 index 31f3049..0000000 --- a/MachineLearning_Engine/Compute/Structured/LogisticRegression.cs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.Engine.MachineLearning; -using BH.oM.MachineLearning; -using BH.oM.Base; -using BH.oM.Base.Attributes; -using Python.Runtime; -using System; -using System.Linq; -using System.Collections.Generic; -using System.ComponentModel; - -namespace BH.Engine.MachineLearning.Structured -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Finds the slope and the intercept of a linear function that best fits the given set of bidimensional data.")] - [Input("x", "Training data as a list of 2-elements list.")] - [Input("y", "Target values as a list of 2-elements list.")] - [Output("model", "The ordinary least squares linear regression with the given data.")] - public static LogisticRegression LogisticRegression(Tensor x, Tensor y) - { - PyObject model = BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "LogisticRegression.fit", x, y); - return new LogisticRegression(model); - } - - /*************************************/ - - [Description("Projects the given input using a linear regression model.")] - [Input("model", "The linear regressor model used for inference.")] - [Input("x", "Data to project on.")] - [Output("y", "The projected output for the given data using the linear model.")] - public static Tensor Infer(LogisticRegression model, Tensor x) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "LogisticRegression.infer", model, x)); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Structured/LogisticRegression.py b/MachineLearning_Engine/Compute/Structured/LogisticRegression.py deleted file mode 100644 index 974ac4a..0000000 --- a/MachineLearning_Engine/Compute/Structured/LogisticRegression.py +++ /dev/null @@ -1,56 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from sklearn.linear_model import LogisticRegression -import numpy as np - - -def fit(x: np.ndarray, y: np.ndarray): - assert len(x) == len(y), "Input data and target data have different length {} and {}".format( - len(x), len(y)) - - # instantiace logistic regression model - model = LogisticRegression() - - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - if y.ndim == 1: - y = y.reshape(-1, 1) - - # fit the training data - model.fit(x, y) - return model - -def infer(model: LogisticRegression, x: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - return model.predict(x) - -def score(model: LogisticRegression, x: np.ndarray, y: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - if y.ndim == 1: - y = y.reshape(-1, 1) - return model.score(x, y) \ No newline at end of file diff --git a/MachineLearning_Engine/Compute/Structured/Score.cs b/MachineLearning_Engine/Compute/Structured/Score.cs deleted file mode 100644 index badb543..0000000 --- a/MachineLearning_Engine/Compute/Structured/Score.cs +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using BH.oM.Base; -using BH.oM.Base.Attributes; -using BH.Engine.MachineLearning; -using System; -using System.Linq; -using System.Collections.Generic; -using System.ComponentModel; - -namespace BH.Engine.MachineLearning.Structured -{ - public static partial class Compute - { - /*************************************/ - /**** Public Fields ****/ - /*************************************/ - - [Description("Finds the The coefficient of determination R^2 of the given regression model.")] - [Input("model", "The regression model used for inference.")] - [Input("x", "Training data as a list of 2-elements list.")] - [Input("y", "Target values as a list of 2-elements list.")] - [Output("r2", "The coefficient of determination R^2 of the prediction.")] - public static Tensor Score(IRegressionModel model, Tensor x, Tensor y) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, model.GetType().Name.ToString() + ".score", model, x, y)); - } - } -} - - diff --git a/MachineLearning_Engine/Compute/Structured/SupportVectorRegression.cs b/MachineLearning_Engine/Compute/Structured/SupportVectorRegression.cs deleted file mode 100644 index fa08dc3..0000000 --- a/MachineLearning_Engine/Compute/Structured/SupportVectorRegression.cs +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.Engine.MachineLearning; -using BH.oM.MachineLearning; -using BH.oM.Base; -using BH.oM.Base.Attributes; -using Python.Runtime; -using System; -using System.Linq; -using System.Collections.Generic; -using System.ComponentModel; - -namespace BH.Engine.MachineLearning.Structured -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static SupportVectorRegression SupportVectorRegression(Tensor x, Tensor y, string kernel = "rbf", int degree = 3, double regularisation = 1.0) - { - PyObject model = BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "SupportVectorRegression.fit", x, y, kernel, degree, regularisation); - return new SupportVectorRegression(model); - } - - /*************************************/ - - public static Tensor Infer(SupportVectorRegression model, Tensor x) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "SupportVectorRegression.infer", model, x)); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Structured/SupportVectorRegression.py b/MachineLearning_Engine/Compute/Structured/SupportVectorRegression.py deleted file mode 100644 index 8920f21..0000000 --- a/MachineLearning_Engine/Compute/Structured/SupportVectorRegression.py +++ /dev/null @@ -1,57 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from sklearn.svm import SVR -import numpy as np - - -def fit(x: np.ndarray, y: np.ndarray, kernel: str, degree: int, regularisation: float): - assert len(x) == len(y), "Input data and target data have different length {} and {}".format( - len(x), len(y)) - - # instantiace linear regression model - model = SVR(kernel=kernel, degree=degree, C=regularisation) - - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - if y.ndim == 1: - y = y.reshape(-1, 1) - - # fit the training data - model.fit(x, y) - return model - -def infer(model: SVR, x: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - return model.predict(x) - - -def score(model: SVR, x: np.ndarray, y: np.ndarray): - # make sure the input is at least bidimensinal - if x.ndim == 1: - x = x.reshape(-1, 1) - if y.ndim == 1: - y = y.reshape(-1, 1) - return model.score(x, y) \ No newline at end of file diff --git a/MachineLearning_Engine/Compute/Structured/__init__.py b/MachineLearning_Engine/Compute/Structured/__init__.py deleted file mode 100644 index c6d664e..0000000 --- a/MachineLearning_Engine/Compute/Structured/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from . import LinearRegression -from . import SupportVectorRegression -from . import LogisticRegression diff --git a/MachineLearning_Engine/Compute/Text/Answer.cs b/MachineLearning_Engine/Compute/Text/Answer.cs deleted file mode 100644 index 1bc269d..0000000 --- a/MachineLearning_Engine/Compute/Text/Answer.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -namespace BH.Engine.MachineLearning.Text -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static string Answer(string question, string context = "") - { - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "Answer.infer", question, context).As(); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Text/Answer.py b/MachineLearning_Engine/Compute/Text/Answer.py deleted file mode 100644 index 811e8b1..0000000 --- a/MachineLearning_Engine/Compute/Text/Answer.py +++ /dev/null @@ -1,45 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import torch -from transformers import pipeline - - -def infer(question: str, context: str): - # load model - global Q_A_PIPELINE - if Q_A_PIPELINE is None: - Q_A_PIPELINE = pipeline('question-answering') - - output = Q_A_PIPELINE({ - "question": question, - "context": context - })[0] - - start = output.get("start") - end = output.get("end") - score = output.get("score") - answer = output.get("answer") - - return answer - -Q_A_PIPELINE = None diff --git a/MachineLearning_Engine/Compute/Text/SentimentAnalysis.cs b/MachineLearning_Engine/Compute/Text/SentimentAnalysis.cs deleted file mode 100644 index c2e55eb..0000000 --- a/MachineLearning_Engine/Compute/Text/SentimentAnalysis.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -namespace BH.Engine.MachineLearning.Text -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static double SentimentAnalysis(string text) - { - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "SentimentAnalysis.infer", text).As(); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Text/SentimentAnalysis.py b/MachineLearning_Engine/Compute/Text/SentimentAnalysis.py deleted file mode 100644 index 5063aab..0000000 --- a/MachineLearning_Engine/Compute/Text/SentimentAnalysis.py +++ /dev/null @@ -1,38 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import torch -from transformers import pipeline - - -def infer(text: str): - global SENTIMENT_ANALYSIS_PIPELINE - if SENTIMENT_ANALYSIS_PIPELINE is None: - SENTIMENT_ANALYSIS_PIPELINE = pipeline('sentiment-analysis') - - output = SENTIMENT_ANALYSIS_PIPELINE(text)[0] - sentiment = 1 if output.get("label") == "POSITIVE" else -1 - score = output.get("score") - - return score * sentiment - -SENTIMENT_ANALYSIS_PIPELINE = None diff --git a/MachineLearning_Engine/Compute/Text/Summarise.cs b/MachineLearning_Engine/Compute/Text/Summarise.cs deleted file mode 100644 index 916a586..0000000 --- a/MachineLearning_Engine/Compute/Text/Summarise.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -namespace BH.Engine.MachineLearning.Text -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static string Summarise(string text) - { - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "Summarise.infer", text).As(); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Text/Summarise.py b/MachineLearning_Engine/Compute/Text/Summarise.py deleted file mode 100644 index bda7429..0000000 --- a/MachineLearning_Engine/Compute/Text/Summarise.py +++ /dev/null @@ -1,36 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from transformers import pipeline - - -def infer(text: str): - global summarisation_pipeline - if summarisation_pipeline is None: - summarisation_pipeline = pipeline('summarization') - - output = summarisation_pipeline(text)[0] - summary_text = output.get("summary_text") - - return summary_text - -summarisation_pipeline = None diff --git a/MachineLearning_Engine/Compute/Text/__init__.py b/MachineLearning_Engine/Compute/Text/__init__.py deleted file mode 100644 index 0734382..0000000 --- a/MachineLearning_Engine/Compute/Text/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from . import Answer -from . import SentimentAnalysis -from . import Summarise \ No newline at end of file diff --git a/MachineLearning_Engine/Compute/Vision/DetectObjects.cs b/MachineLearning_Engine/Compute/Vision/DetectObjects.cs deleted file mode 100644 index 723f512..0000000 --- a/MachineLearning_Engine/Compute/Vision/DetectObjects.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -namespace BH.Engine.MachineLearning.Vision -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static object DetectObjects(string imagePath, bool gpu = false, double scoreThreshold = 0.9) - { - return BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "DetectObjects.infer", imagePath, gpu, scoreThreshold); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Vision/DetectObjects.py b/MachineLearning_Engine/Compute/Vision/DetectObjects.py deleted file mode 100644 index e9014aa..0000000 --- a/MachineLearning_Engine/Compute/Vision/DetectObjects.py +++ /dev/null @@ -1,49 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import os -import PIL -import torch -import torchvision - - -def infer(image_path: str, gpu: bool, score_threshold: float): - if not (os.path.isfile(image_path)): - raise FileNotFoundError(image_path) - - global model - if model is None: - model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True, pretrained_backbone=True) - model.eval() - - pil_image: PIL.Image.Image = PIL.Image.open(image_path) - tensor_image: torch.Tensor = torchvision.transforms.functional.to_tensor(pil_image) - - if gpu: - tensor_image = tensor_image.cuda() - model = model.cuda() - - with torch.no_grad(): - detection: List[Dict[str, torch.Tensor]] = model(tensor_image.unsqueeze(0)) - return detection[0] - -model = None diff --git a/MachineLearning_Engine/Compute/Vision/DrawDetection.cs b/MachineLearning_Engine/Compute/Vision/DrawDetection.cs deleted file mode 100644 index 9905092..0000000 --- a/MachineLearning_Engine/Compute/Vision/DrawDetection.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using Python.Runtime; - -namespace BH.Engine.MachineLearning.Vision -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static Tensor DrawDetection(string imagePath, PyObject detection, double minAccuracy=0.8) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "DrawDetection.draw_detection", imagePath, detection, minAccuracy)); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Vision/DrawDetection.py b/MachineLearning_Engine/Compute/Vision/DrawDetection.py deleted file mode 100644 index 5893d92..0000000 --- a/MachineLearning_Engine/Compute/Vision/DrawDetection.py +++ /dev/null @@ -1,226 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import PIL -import PIL.ImageDraw -import PIL.ImageFont -import torch -import torchvision - - -def draw_detection(image_path: str, detection, category: str=None, min_accuracy: float=0.9): - image = PIL.Image.open(image_path) - draw = PIL.ImageDraw.Draw(image) - for i, rect in enumerate(detection["boxes"]): - if detection["scores"][i] < min_accuracy: - continue - draw.rectangle(((rect[0], rect[1]), (rect[2], rect[3])), outline="red") - draw.text((rect[0], rect[1]), coco_labels[int( - detection["labels"][i])], font=PIL.ImageFont.truetype("arial", 20), fill="red") - return torchvision.transforms.functional.to_tensor(image) - - -coco_labels = { - 0: "unlabeled", - 1: "person", - 2: "bicycle", - 3: "car", - 4: "motorcycle", - 5: "airplane", - 6: "bus", - 7: "train", - 8: "truck", - 9: "boat", - 10: "traffic light", - 11: "fire hydrant", - 12: "street sign", - 13: "stop sign", - 14: "parking meter", - 15: "bench", - 16: "bird", - 17: "cat", - 18: "dog", - 19: "horse", - 20: "sheep", - 21: "cow", - 22: "elephant", - 23: "bear", - 24: "zebra", - 25: "giraffe", - 26: "hat", - 27: "backpack", - 28: "umbrella", - 29: "shoe", - 30: "eye glasses", - 31: "handbag", - 32: "tie", - 33: "suitcase", - 34: "frisbee", - 35: "skis", - 36: "snowboard", - 37: "sports ball", - 38: "kite", - 39: "baseball bat", - 40: "baseball glove", - 41: "skateboard", - 42: "surfboard", - 43: "tennis racket", - 44: "bottle", - 45: "plate", - 46: "wine glass", - 47: "cup", - 48: "fork", - 49: "knife", - 50: "spoon", - 51: "bowl", - 52: "banana", - 53: "apple", - 54: "sandwich", - 55: "orange", - 56: "broccoli", - 57: "carrot", - 58: "hot dog", - 59: "pizza", - 60: "donut", - 61: "cake", - 62: "chair", - 63: "couch", - 64: "potted plant", - 65: "bed", - 66: "mirror", - 67: "dining table", - 68: "window", - 69: "desk", - 70: "toilet", - 71: "door", - 72: "tv", - 73: "laptop", - 74: "mouse", - 75: "remote", - 76: "keyboard", - 77: "cell phone", - 78: "microwave", - 79: "oven", - 80: "toaster", - 81: "sink", - 82: "refrigerator", - 83: "blender", - 84: "book", - 85: "clock", - 86: "vase", - 87: "scissors", - 88: "teddy bear", - 89: "hair drier", - 90: "toothbrush", - 91: "hair brush", - 92: "banner", - 93: "blanket", - 94: "branch", - 95: "bridge", - 96: "building-other", - 97: "bush", - 98: "cabinet", - 99: "cage", - 100: "cardboard", - 101: "carpet", - 102: "ceiling-other", - 103: "ceiling-tile", - 104: "cloth", - 105: "clothes", - 106: "clouds", - 107: "counter", - 108: "cupboard", - 109: "curtain", - 110: "desk-stuff", - 111: "dirt", - 112: "door-stuff", - 113: "fence", - 114: "floor-marble", - 115: "floor-other", - 116: "floor-stone", - 117: "floor-tile", - 118: "floor-wood", - 119: "flower", - 120: "fog", - 121: "food-other", - 122: "fruit", - 123: "furniture-other", - 124: "grass", - 125: "gravel", - 126: "ground-other", - 127: "hill", - 128: "house", - 129: "leaves", - 130: "light", - 131: "mat", - 132: "metal", - 133: "mirror-stuff", - 134: "moss", - 135: "mountain", - 136: "mud", - 137: "napkin", - 138: "net", - 139: "paper", - 140: "pavement", - 141: "pillow", - 142: "plant-other", - 143: "plastic", - 144: "platform", - 145: "playingfield", - 146: "railing", - 147: "railroad", - 148: "river", - 149: "road", - 150: "rock", - 151: "roof", - 152: "rug", - 153: "salad", - 154: "sand", - 155: "sea", - 156: "shelf", - 157: "sky-other", - 158: "skyscraper", - 159: "snow", - 160: "solid-other", - 161: "stairs", - 162: "stone", - 163: "straw", - 164: "structural-other", - 165: "table", - 166: "tent", - 167: "textile-other", - 168: "towel", - 169: "tree", - 170: "vegetable", - 171: "wall-brick", - 172: "wall-concrete", - 173: "wall-other", - 174: "wall-panel", - 175: "wall-stone", - 176: "wall-tile", - 177: "wall-wood", - 178: "water-other", - 179: "waterdrops", - 180: "window-blind", - 181: "window-other", - 182: "wood", - } diff --git a/MachineLearning_Engine/Compute/Vision/FindContours.cs b/MachineLearning_Engine/Compute/Vision/FindContours.cs deleted file mode 100644 index 2cf6d70..0000000 --- a/MachineLearning_Engine/Compute/Vision/FindContours.cs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.Engine.Python; -using BH.oM.Geometry; -using BH.oM.MachineLearning; -using Python.Runtime; -using System.Collections.Generic; - -namespace BH.Engine.MachineLearning.Vision -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static List FindContours(Tensor image, int level) - { - List polylines = new List(); - // returns a list of points as numpy arrays - List contours = (BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "FindContours.infer", image, level).IFromPython()) as List; - foreach (List> polyline in contours) - { - Polyline bhomPolyline = new Polyline(); - foreach(List point in polyline) - { - Point bhomPoint = new Point { X = point[0], Y = point[1] }; - bhomPolyline.ControlPoints.Add(bhomPoint); - } - polylines.Add(bhomPolyline); - } - return polylines; - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Vision/FindContours.py b/MachineLearning_Engine/Compute/Vision/FindContours.py deleted file mode 100644 index 25699cf..0000000 --- a/MachineLearning_Engine/Compute/Vision/FindContours.py +++ /dev/null @@ -1,58 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import numpy as np -import matplotlib.pyplot as plt -import skimage.measure -import skimage.color -import torch - - -def infer(im: np.ndarray, level: int): - if torch.is_tensor(im): - im = im.detach().cpu().numpy() - - im = im.squeeze() - ndim = im.ndim - - if ndim == 2: - return skimage.measure.find_contours(im, level) - - if ndim == 3: - # case: RGB image, channel first - if im.size(0) == 3: - im = np.transpose(im, (2, 1, 0)) - return skimage.measure.find_contours(im, level) - # case: RGB image, channel last - elif im.size(2) == 3: - mask = skimage.color.rgb2gray(im) - return skimage.measure.find_contours(im, level) - # case: list of grayscale images - elif 3 not in im.shape: - return [infer(x, level) for x in im] - - if ndim == 4: - # the only case is a list of images, rgb or grayscale with channels 1 - return [infer(x, level) for x in im] - - raise ValueError("I really don't know what you want to do with a tensor {}".format(im.shape)) - return diff --git a/MachineLearning_Engine/Compute/Vision/RecogniseObject.py b/MachineLearning_Engine/Compute/Vision/RecogniseObject.py deleted file mode 100644 index 60559b7..0000000 --- a/MachineLearning_Engine/Compute/Vision/RecogniseObject.py +++ /dev/null @@ -1,1058 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import os -import PIL -import torch -import torchvision - - -def infer(image_path: str, gpu: bool=False): - if not (os.path.isfile(image_path)): - raise FileNotFoundError(image_path) - - global model - if model is None: - model = torchvision.models.inception_v3(pretrained=True) - model.eval() - - pil_image: PIL.Image.Image = PIL.Image.open(image_path) - tensor_image: torch.Tensor = torchvision.transforms.functional.to_tensor(pil_image) - - if gpu: - tensor_image = tensor_image.cuda() - model = model.cuda() - else: - tensor_image = tensor_image.cpu() - model = model.cpu() - - with torch.no_grad(): - detection: List[Dict[str, torch.Tensor]] = model(tensor_image.unsqueeze(0)) - - label = torch.argmax(detection, dim=1).squeeze().item() - return labels.get(label, None) - - -model = None - -labels = { - 0: 'tench, Tinca tinca', - 1: 'goldfish, Carassius auratus', - 2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias', - 3: 'tiger shark, Galeocerdo cuvieri', - 4: 'hammerhead, hammerhead shark', - 5: 'electric ray, crampfish, numbfish, torpedo', - 6: 'stingray', - 7: 'cock', - 8: 'hen', - 9: 'ostrich, Struthio camelus', - 10: 'brambling, Fringilla montifringilla', - 11: 'goldfinch, Carduelis carduelis', - 12: 'house finch, linnet, Carpodacus mexicanus', - 13: 'junco, snowbird', - 14: 'indigo bunting, indigo finch, indigo bird, Passerina cyanea', - 15: 'robin, American robin, Turdus migratorius', - 16: 'bulbul', - 17: 'jay', - 18: 'magpie', - 19: 'chickadee', - 20: 'water ouzel, dipper', - 21: 'kite', - 22: 'bald eagle, American eagle, Haliaeetus leucocephalus', - 23: 'vulture', - 24: 'great grey owl, great gray owl, Strix nebulosa', - 25: 'European fire salamander, Salamandra salamandra', - 26: 'common newt, Triturus vulgaris', - 27: 'eft', - 28: 'spotted salamander, Ambystoma maculatum', - 29: 'axolotl, mud puppy, Ambystoma mexicanum', - 30: 'bullfrog, Rana catesbeiana', - 31: 'tree frog, tree-frog', - 32: 'tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui', - 33: 'loggerhead, loggerhead turtle, Caretta caretta', - 34: 'leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea', - 35: 'mud turtle', - 36: 'terrapin', - 37: 'box turtle, box tortoise', - 38: 'banded gecko', - 39: 'common iguana, iguana, Iguana iguana', - 40: 'American chameleon, anole, Anolis carolinensis', - 41: 'whiptail, whiptail lizard', - 42: 'agama', - 43: 'frilled lizard, Chlamydosaurus kingi', - 44: 'alligator lizard', - 45: 'Gila monster, Heloderma suspectum', - 46: 'green lizard, Lacerta viridis', - 47: 'African chameleon, Chamaeleo chamaeleon', - 48: 'Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis', - 49: 'African crocodile, Nile crocodile, Crocodylus niloticus', - 50: 'American alligator, Alligator mississipiensis', - 51: 'triceratops', - 52: 'thunder snake, worm snake, Carphophis amoenus', - 53: 'ringneck snake, ring-necked snake, ring snake', - 54: 'hognose snake, puff adder, sand viper', - 55: 'green snake, grass snake', - 56: 'king snake, kingsnake', - 57: 'garter snake, grass snake', - 58: 'water snake', - 59: 'vine snake', - 60: 'night snake, Hypsiglena torquata', - 61: 'boa constrictor, Constrictor constrictor', - 62: 'rock python, rock snake, Python sebae', - 63: 'Indian cobra, Naja naja', - 64: 'green mamba', - 65: 'sea snake', - 66: 'horned viper, cerastes, sand viper, horned asp, Cerastes cornutus', - 67: 'diamondback, diamondback rattlesnake, Crotalus adamanteus', - 68: 'sidewinder, horned rattlesnake, Crotalus cerastes', - 69: 'trilobite', - 70: 'harvestman, daddy longlegs, Phalangium opilio', - 71: 'scorpion', - 72: 'black and gold garden spider, Argiope aurantia', - 73: 'barn spider, Araneus cavaticus', - 74: 'garden spider, Aranea diademata', - 75: 'black widow, Latrodectus mactans', - 76: 'tarantula', - 77: 'wolf spider, hunting spider', - 78: 'tick', - 79: 'centipede', - 80: 'black grouse', - 81: 'ptarmigan', - 82: 'ruffed grouse, partridge, Bonasa umbellus', - 83: 'prairie chicken, prairie grouse, prairie fowl', - 84: 'peacock', - 85: 'quail', - 86: 'partridge', - 87: 'African grey, African gray, Psittacus erithacus', - 88: 'macaw', - 89: 'sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita', - 90: 'lorikeet', - 91: 'coucal', - 92: 'bee eater', - 93: 'hornbill', - 94: 'hummingbird', - 95: 'jacamar', - 96: 'toucan', - 97: 'drake', - 98: 'red-breasted merganser, Mergus serrator', - 99: 'goose', - 100: 'black swan, Cygnus atratus', - 101: 'tusker', - 102: 'echidna, spiny anteater, anteater', - 103: 'platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus', - 104: 'wallaby, brush kangaroo', - 105: 'koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus', - 106: 'wombat', - 107: 'jellyfish', - 108: 'sea anemone, anemone', - 109: 'brain coral', - 110: 'flatworm, platyhelminth', - 111: 'nematode, nematode worm, roundworm', - 112: 'conch', - 113: 'snail', - 114: 'slug', - 115: 'sea slug, nudibranch', - 116: 'chiton, coat-of-mail shell, sea cradle, polyplacophore', - 117: 'chambered nautilus, pearly nautilus, nautilus', - 118: 'Dungeness crab, Cancer magister', - 119: 'rock crab, Cancer irroratus', - 120: 'fiddler crab', - 121: 'king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica', - 122: 'American lobster, Northern lobster, Maine lobster, Homarus americanus', - 123: 'spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish', - 124: 'crayfish, crawfish, crawdad, crawdaddy', - 125: 'hermit crab', - 126: 'isopod', - 127: 'white stork, Ciconia ciconia', - 128: 'black stork, Ciconia nigra', - 129: 'spoonbill', - 130: 'flamingo', - 131: 'little blue heron, Egretta caerulea', - 132: 'American egret, great white heron, Egretta albus', - 133: 'bittern', - 134: 'crane', - 135: 'limpkin, Aramus pictus', - 136: 'European gallinule, Porphyrio porphyrio', - 137: 'American coot, marsh hen, mud hen, water hen, Fulica americana', - 138: 'bustard', - 139: 'ruddy turnstone, Arenaria interpres', - 140: 'red-backed sandpiper, dunlin, Erolia alpina', - 141: 'redshank, Tringa totanus', - 142: 'dowitcher', - 143: 'oystercatcher, oyster catcher', - 144: 'pelican', - 145: 'king penguin, Aptenodytes patagonica', - 146: 'albatross, mollymawk', - 147: 'grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus', - 148: 'killer whale, killer, orca, grampus, sea wolf, Orcinus orca', - 149: 'dugong, Dugong dugon', - 150: 'sea lion', - 151: 'Chihuahua', - 152: 'Japanese spaniel', - 153: 'Maltese dog, Maltese terrier, Maltese', - 154: 'Pekinese, Pekingese, Peke', - 155: 'Shih-Tzu', - 156: 'Blenheim spaniel', - 157: 'papillon', - 158: 'toy terrier', - 159: 'Rhodesian ridgeback', - 160: 'Afghan hound, Afghan', - 161: 'basset, basset hound', - 162: 'beagle', - 163: 'bloodhound, sleuthhound', - 164: 'bluetick', - 165: 'black-and-tan coonhound', - 166: 'Walker hound, Walker foxhound', - 167: 'English foxhound', - 168: 'redbone', - 169: 'borzoi, Russian wolfhound', - 170: 'Irish wolfhound', - 171: 'Italian greyhound', - 172: 'whippet', - 173: 'Ibizan hound, Ibizan Podenco', - 174: 'Norwegian elkhound, elkhound', - 175: 'otterhound, otter hound', - 176: 'Saluki, gazelle hound', - 177: 'Scottish deerhound, deerhound', - 178: 'Weimaraner', - 179: 'Staffordshire bullterrier, Staffordshire bull terrier', - 180: 'American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier', - 181: 'Bedlington terrier', - 182: 'Border terrier', - 183: 'Kerry blue terrier', - 184: 'Irish terrier', - 185: 'Norfolk terrier', - 186: 'Norwich terrier', - 187: 'Yorkshire terrier', - 188: 'wire-haired fox terrier', - 189: 'Lakeland terrier', - 190: 'Sealyham terrier, Sealyham', - 191: 'Airedale, Airedale terrier', - 192: 'cairn, cairn terrier', - 193: 'Australian terrier', - 194: 'Dandie Dinmont, Dandie Dinmont terrier', - 195: 'Boston bull, Boston terrier', - 196: 'miniature schnauzer', - 197: 'giant schnauzer', - 198: 'standard schnauzer', - 199: 'Scotch terrier, Scottish terrier, Scottie', - 200: 'Tibetan terrier, chrysanthemum dog', - 201: 'silky terrier, Sydney silky', - 202: 'soft-coated wheaten terrier', - 203: 'West Highland white terrier', - 204: 'Lhasa, Lhasa apso', - 205: 'flat-coated retriever', - 206: 'curly-coated retriever', - 207: 'golden retriever', - 208: 'Labrador retriever', - 209: 'Chesapeake Bay retriever', - 210: 'German short-haired pointer', - 211: 'vizsla, Hungarian pointer', - 212: 'English setter', - 213: 'Irish setter, red setter', - 214: 'Gordon setter', - 215: 'Brittany spaniel', - 216: 'clumber, clumber spaniel', - 217: 'English springer, English springer spaniel', - 218: 'Welsh springer spaniel', - 219: 'cocker spaniel, English cocker spaniel, cocker', - 220: 'Sussex spaniel', - 221: 'Irish water spaniel', - 222: 'kuvasz', - 223: 'schipperke', - 224: 'groenendael', - 225: 'malinois', - 226: 'briard', - 227: 'kelpie', - 228: 'komondor', - 229: 'Old English sheepdog, bobtail', - 230: 'Shetland sheepdog, Shetland sheep dog, Shetland', - 231: 'collie', - 232: 'Border collie', - 233: 'Bouvier des Flandres, Bouviers des Flandres', - 234: 'Rottweiler', - 235: 'German shepherd, German shepherd dog, German police dog, alsatian', - 236: 'Doberman, Doberman pinscher', - 237: 'miniature pinscher', - 238: 'Greater Swiss Mountain dog', - 239: 'Bernese mountain dog', - 240: 'Appenzeller', - 241: 'EntleBucher', - 242: 'boxer', - 243: 'bull mastiff', - 244: 'Tibetan mastiff', - 245: 'French bulldog', - 246: 'Great Dane', - 247: 'Saint Bernard, St Bernard', - 248: 'Eskimo dog, husky', - 249: 'malamute, malemute, Alaskan malamute', - 250: 'Siberian husky', - 251: 'dalmatian, coach dog, carriage dog', - 252: 'affenpinscher, monkey pinscher, monkey dog', - 253: 'basenji', - 254: 'pug, pug-dog', - 255: 'Leonberg', - 256: 'Newfoundland, Newfoundland dog', - 257: 'Great Pyrenees', - 258: 'Samoyed, Samoyede', - 259: 'Pomeranian', - 260: 'chow, chow chow', - 261: 'keeshond', - 262: 'Brabancon griffon', - 263: 'Pembroke, Pembroke Welsh corgi', - 264: 'Cardigan, Cardigan Welsh corgi', - 265: 'toy poodle', - 266: 'miniature poodle', - 267: 'standard poodle', - 268: 'Mexican hairless', - 269: 'timber wolf, grey wolf, gray wolf, Canis lupus', - 270: 'white wolf, Arctic wolf, Canis lupus tundrarum', - 271: 'red wolf, maned wolf, Canis rufus, Canis niger', - 272: 'coyote, prairie wolf, brush wolf, Canis latrans', - 273: 'dingo, warrigal, warragal, Canis dingo', - 274: 'dhole, Cuon alpinus', - 275: 'African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus', - 276: 'hyena, hyaena', - 277: 'red fox, Vulpes vulpes', - 278: 'kit fox, Vulpes macrotis', - 279: 'Arctic fox, white fox, Alopex lagopus', - 280: 'grey fox, gray fox, Urocyon cinereoargenteus', - 281: 'tabby, tabby cat', - 282: 'tiger cat', - 283: 'Persian cat', - 284: 'Siamese cat, Siamese', - 285: 'Egyptian cat', - 286: 'cougar, puma, catamount, mountain lion, painter, panther, Felis concolor', - 287: 'lynx, catamount', - 288: 'leopard, Panthera pardus', - 289: 'snow leopard, ounce, Panthera uncia', - 290: 'jaguar, panther, Panthera onca, Felis onca', - 291: 'lion, king of beasts, Panthera leo', - 292: 'tiger, Panthera tigris', - 293: 'cheetah, chetah, Acinonyx jubatus', - 294: 'brown bear, bruin, Ursus arctos', - 295: 'American black bear, black bear, Ursus americanus, Euarctos americanus', - 296: 'ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus', - 297: 'sloth bear, Melursus ursinus, Ursus ursinus', - 298: 'mongoose', - 299: 'meerkat, mierkat', - 300: 'tiger beetle', - 301: 'ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle', - 302: 'ground beetle, carabid beetle', - 303: 'long-horned beetle, longicorn, longicorn beetle', - 304: 'leaf beetle, chrysomelid', - 305: 'dung beetle', - 306: 'rhinoceros beetle', - 307: 'weevil', - 308: 'fly', - 309: 'bee', - 310: 'ant, emmet, pismire', - 311: 'grasshopper, hopper', - 312: 'cricket', - 313: 'walking stick, walkingstick, stick insect', - 314: 'cockroach, roach', - 315: 'mantis, mantid', - 316: 'cicada, cicala', - 317: 'leafhopper', - 318: 'lacewing, lacewing fly', - 319: "dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk", - 320: 'damselfly', - 321: 'admiral', - 322: 'ringlet, ringlet butterfly', - 323: 'monarch, monarch butterfly, milkweed butterfly, Danaus plexippus', - 324: 'cabbage butterfly', - 325: 'sulphur butterfly, sulfur butterfly', - 326: 'lycaenid, lycaenid butterfly', - 327: 'starfish, sea star', - 328: 'sea urchin', - 329: 'sea cucumber, holothurian', - 330: 'wood rabbit, cottontail, cottontail rabbit', - 331: 'hare', - 332: 'Angora, Angora rabbit', - 333: 'hamster', - 334: 'porcupine, hedgehog', - 335: 'fox squirrel, eastern fox squirrel, Sciurus niger', - 336: 'marmot', - 337: 'beaver', - 338: 'guinea pig, Cavia cobaya', - 339: 'sorrel', - 340: 'zebra', - 341: 'hog, pig, grunter, squealer, Sus scrofa', - 342: 'wild boar, boar, Sus scrofa', - 343: 'warthog', - 344: 'hippopotamus, hippo, river horse, Hippopotamus amphibius', - 345: 'ox', - 346: 'water buffalo, water ox, Asiatic buffalo, Bubalus bubalis', - 347: 'bison', - 348: 'ram, tup', - 349: 'bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis', - 350: 'ibex, Capra ibex', - 351: 'hartebeest', - 352: 'impala, Aepyceros melampus', - 353: 'gazelle', - 354: 'Arabian camel, dromedary, Camelus dromedarius', - 355: 'llama', - 356: 'weasel', - 357: 'mink', - 358: 'polecat, fitch, foulmart, foumart, Mustela putorius', - 359: 'black-footed ferret, ferret, Mustela nigripes', - 360: 'otter', - 361: 'skunk, polecat, wood pussy', - 362: 'badger', - 363: 'armadillo', - 364: 'three-toed sloth, ai, Bradypus tridactylus', - 365: 'orangutan, orang, orangutang, Pongo pygmaeus', - 366: 'gorilla, Gorilla gorilla', - 367: 'chimpanzee, chimp, Pan troglodytes', - 368: 'gibbon, Hylobates lar', - 369: 'siamang, Hylobates syndactylus, Symphalangus syndactylus', - 370: 'guenon, guenon monkey', - 371: 'patas, hussar monkey, Erythrocebus patas', - 372: 'baboon', - 373: 'macaque', - 374: 'langur', - 375: 'colobus, colobus monkey', - 376: 'proboscis monkey, Nasalis larvatus', - 377: 'marmoset', - 378: 'capuchin, ringtail, Cebus capucinus', - 379: 'howler monkey, howler', - 380: 'titi, titi monkey', - 381: 'spider monkey, Ateles geoffroyi', - 382: 'squirrel monkey, Saimiri sciureus', - 383: 'Madagascar cat, ring-tailed lemur, Lemur catta', - 384: 'indri, indris, Indri indri, Indri brevicaudatus', - 385: 'Indian elephant, Elephas maximus', - 386: 'African elephant, Loxodonta africana', - 387: 'lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens', - 388: 'giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca', - 389: 'barracouta, snoek', - 390: 'eel', - 391: 'coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch', - 392: 'rock beauty, Holocanthus tricolor', - 393: 'anemone fish', - 394: 'sturgeon', - 395: 'gar, garfish, garpike, billfish, Lepisosteus osseus', - 396: 'lionfish', - 397: 'puffer, pufferfish, blowfish, globefish', - 398: 'abacus', - 399: 'abaya', - 400: "academic gown, academic robe, judge's robe", - 401: 'accordion, piano accordion, squeeze box', - 402: 'acoustic guitar', - 403: 'aircraft carrier, carrier, flattop, attack aircraft carrier', - 404: 'airliner', - 405: 'airship, dirigible', - 406: 'altar', - 407: 'ambulance', - 408: 'amphibian, amphibious vehicle', - 409: 'analog clock', - 410: 'apiary, bee house', - 411: 'apron', - 412: 'ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin', - 413: 'assault rifle, assault gun', - 414: 'backpack, back pack, knapsack, packsack, rucksack, haversack', - 415: 'bakery, bakeshop, bakehouse', - 416: 'balance beam, beam', - 417: 'balloon', - 418: 'ballpoint, ballpoint pen, ballpen, Biro', - 419: 'Band Aid', - 420: 'banjo', - 421: 'bannister, banister, balustrade, balusters, handrail', - 422: 'barbell', - 423: 'barber chair', - 424: 'barbershop', - 425: 'barn', - 426: 'barometer', - 427: 'barrel, cask', - 428: 'barrow, garden cart, lawn cart, wheelbarrow', - 429: 'baseball', - 430: 'basketball', - 431: 'bassinet', - 432: 'bassoon', - 433: 'bathing cap, swimming cap', - 434: 'bath towel', - 435: 'bathtub, bathing tub, bath, tub', - 436: 'beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon', - 437: 'beacon, lighthouse, beacon light, pharos', - 438: 'beaker', - 439: 'bearskin, busby, shako', - 440: 'beer bottle', - 441: 'beer glass', - 442: 'bell cote, bell cot', - 443: 'bib', - 444: 'bicycle-built-for-two, tandem bicycle, tandem', - 445: 'bikini, two-piece', - 446: 'binder, ring-binder', - 447: 'binoculars, field glasses, opera glasses', - 448: 'birdhouse', - 449: 'boathouse', - 450: 'bobsled, bobsleigh, bob', - 451: 'bolo tie, bolo, bola tie, bola', - 452: 'bonnet, poke bonnet', - 453: 'bookcase', - 454: 'bookshop, bookstore, bookstall', - 455: 'bottlecap', - 456: 'bow', - 457: 'bow tie, bow-tie, bowtie', - 458: 'brass, memorial tablet, plaque', - 459: 'brassiere, bra, bandeau', - 460: 'breakwater, groin, groyne, mole, bulwark, seawall, jetty', - 461: 'breastplate, aegis, egis', - 462: 'broom', - 463: 'bucket, pail', - 464: 'buckle', - 465: 'bulletproof vest', - 466: 'bullet train, bullet', - 467: 'butcher shop, meat market', - 468: 'cab, hack, taxi, taxicab', - 469: 'caldron, cauldron', - 470: 'candle, taper, wax light', - 471: 'cannon', - 472: 'canoe', - 473: 'can opener, tin opener', - 474: 'cardigan', - 475: 'car mirror', - 476: 'carousel, carrousel, merry-go-round, roundabout, whirligig', - 477: "carpenter's kit, tool kit", - 478: 'carton', - 479: 'car wheel', - 480: 'cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM', - 481: 'cassette', - 482: 'cassette player', - 483: 'castle', - 484: 'catamaran', - 485: 'CD player', - 486: 'cello, violoncello', - 487: 'cellular telephone, cellular phone, cellphone, cell, mobile phone', - 488: 'chain', - 489: 'chainlink fence', - 490: 'chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour', - 491: 'chain saw, chainsaw', - 492: 'chest', - 493: 'chiffonier, commode', - 494: 'chime, bell, gong', - 495: 'china cabinet, china closet', - 496: 'Christmas stocking', - 497: 'church, church building', - 498: 'cinema, movie theater, movie theatre, movie house, picture palace', - 499: 'cleaver, meat cleaver, chopper', - 500: 'cliff dwelling', - 501: 'cloak', - 502: 'clog, geta, patten, sabot', - 503: 'cocktail shaker', - 504: 'coffee mug', - 505: 'coffeepot', - 506: 'coil, spiral, volute, whorl, helix', - 507: 'combination lock', - 508: 'computer keyboard, keypad', - 509: 'confectionery, confectionary, candy store', - 510: 'container ship, containership, container vessel', - 511: 'convertible', - 512: 'corkscrew, bottle screw', - 513: 'cornet, horn, trumpet, trump', - 514: 'cowboy boot', - 515: 'cowboy hat, ten-gallon hat', - 516: 'cradle', - 517: 'crane', - 518: 'crash helmet', - 519: 'crate', - 520: 'crib, cot', - 521: 'Crock Pot', - 522: 'croquet ball', - 523: 'crutch', - 524: 'cuirass', - 525: 'dam, dike, dyke', - 526: 'desk', - 527: 'desktop computer', - 528: 'dial telephone, dial phone', - 529: 'diaper, nappy, napkin', - 530: 'digital clock', - 531: 'digital watch', - 532: 'dining table, board', - 533: 'dishrag, dishcloth', - 534: 'dishwasher, dish washer, dishwashing machine', - 535: 'disk brake, disc brake', - 536: 'dock, dockage, docking facility', - 537: 'dogsled, dog sled, dog sleigh', - 538: 'dome', - 539: 'doormat, welcome mat', - 540: 'drilling platform, offshore rig', - 541: 'drum, membranophone, tympan', - 542: 'drumstick', - 543: 'dumbbell', - 544: 'Dutch oven', - 545: 'electric fan, blower', - 546: 'electric guitar', - 547: 'electric locomotive', - 548: 'entertainment center', - 549: 'envelope', - 550: 'espresso maker', - 551: 'face powder', - 552: 'feather boa, boa', - 553: 'file, file cabinet, filing cabinet', - 554: 'fireboat', - 555: 'fire engine, fire truck', - 556: 'fire screen, fireguard', - 557: 'flagpole, flagstaff', - 558: 'flute, transverse flute', - 559: 'folding chair', - 560: 'football helmet', - 561: 'forklift', - 562: 'fountain', - 563: 'fountain pen', - 564: 'four-poster', - 565: 'freight car', - 566: 'French horn, horn', - 567: 'frying pan, frypan, skillet', - 568: 'fur coat', - 569: 'garbage truck, dustcart', - 570: 'gasmask, respirator, gas helmet', - 571: 'gas pump, gasoline pump, petrol pump, island dispenser', - 572: 'goblet', - 573: 'go-kart', - 574: 'golf ball', - 575: 'golfcart, golf cart', - 576: 'gondola', - 577: 'gong, tam-tam', - 578: 'gown', - 579: 'grand piano, grand', - 580: 'greenhouse, nursery, glasshouse', - 581: 'grille, radiator grille', - 582: 'grocery store, grocery, food market, market', - 583: 'guillotine', - 584: 'hair slide', - 585: 'hair spray', - 586: 'half track', - 587: 'hammer', - 588: 'hamper', - 589: 'hand blower, blow dryer, blow drier, hair dryer, hair drier', - 590: 'hand-held computer, hand-held microcomputer', - 591: 'handkerchief, hankie, hanky, hankey', - 592: 'hard disc, hard disk, fixed disk', - 593: 'harmonica, mouth organ, harp, mouth harp', - 594: 'harp', - 595: 'harvester, reaper', - 596: 'hatchet', - 597: 'holster', - 598: 'home theater, home theatre', - 599: 'honeycomb', - 600: 'hook, claw', - 601: 'hoopskirt, crinoline', - 602: 'horizontal bar, high bar', - 603: 'horse cart, horse-cart', - 604: 'hourglass', - 605: 'iPod', - 606: 'iron, smoothing iron', - 607: "jack-o'-lantern", - 608: 'jean, blue jean, denim', - 609: 'jeep, landrover', - 610: 'jersey, T-shirt, tee shirt', - 611: 'jigsaw puzzle', - 612: 'jinrikisha, ricksha, rickshaw', - 613: 'joystick', - 614: 'kimono', - 615: 'knee pad', - 616: 'knot', - 617: 'lab coat, laboratory coat', - 618: 'ladle', - 619: 'lampshade, lamp shade', - 620: 'laptop, laptop computer', - 621: 'lawn mower, mower', - 622: 'lens cap, lens cover', - 623: 'letter opener, paper knife, paperknife', - 624: 'library', - 625: 'lifeboat', - 626: 'lighter, light, igniter, ignitor', - 627: 'limousine, limo', - 628: 'liner, ocean liner', - 629: 'lipstick, lip rouge', - 630: 'Loafer', - 631: 'lotion', - 632: 'loudspeaker, speaker, speaker unit, loudspeaker system, speaker system', - 633: "loupe, jeweler's loupe", - 634: 'lumbermill, sawmill', - 635: 'magnetic compass', - 636: 'mailbag, postbag', - 637: 'mailbox, letter box', - 638: 'maillot', - 639: 'maillot, tank suit', - 640: 'manhole cover', - 641: 'maraca', - 642: 'marimba, xylophone', - 643: 'mask', - 644: 'matchstick', - 645: 'maypole', - 646: 'maze, labyrinth', - 647: 'measuring cup', - 648: 'medicine chest, medicine cabinet', - 649: 'megalith, megalithic structure', - 650: 'microphone, mike', - 651: 'microwave, microwave oven', - 652: 'military uniform', - 653: 'milk can', - 654: 'minibus', - 655: 'miniskirt, mini', - 656: 'minivan', - 657: 'missile', - 658: 'mitten', - 659: 'mixing bowl', - 660: 'mobile home, manufactured home', - 661: 'Model T', - 662: 'modem', - 663: 'monastery', - 664: 'monitor', - 665: 'moped', - 666: 'mortar', - 667: 'mortarboard', - 668: 'mosque', - 669: 'mosquito net', - 670: 'motor scooter, scooter', - 671: 'mountain bike, all-terrain bike, off-roader', - 672: 'mountain tent', - 673: 'mouse, computer mouse', - 674: 'mousetrap', - 675: 'moving van', - 676: 'muzzle', - 677: 'nail', - 678: 'neck brace', - 679: 'necklace', - 680: 'nipple', - 681: 'notebook, notebook computer', - 682: 'obelisk', - 683: 'oboe, hautboy, hautbois', - 684: 'ocarina, sweet potato', - 685: 'odometer, hodometer, mileometer, milometer', - 686: 'oil filter', - 687: 'organ, pipe organ', - 688: 'oscilloscope, scope, cathode-ray oscilloscope, CRO', - 689: 'overskirt', - 690: 'oxcart', - 691: 'oxygen mask', - 692: 'packet', - 693: 'paddle, boat paddle', - 694: 'paddlewheel, paddle wheel', - 695: 'padlock', - 696: 'paintbrush', - 697: "pajama, pyjama, pj's, jammies", - 698: 'palace', - 699: 'panpipe, pandean pipe, syrinx', - 700: 'paper towel', - 701: 'parachute, chute', - 702: 'parallel bars, bars', - 703: 'park bench', - 704: 'parking meter', - 705: 'passenger car, coach, carriage', - 706: 'patio, terrace', - 707: 'pay-phone, pay-station', - 708: 'pedestal, plinth, footstall', - 709: 'pencil box, pencil case', - 710: 'pencil sharpener', - 711: 'perfume, essence', - 712: 'Petri dish', - 713: 'photocopier', - 714: 'pick, plectrum, plectron', - 715: 'pickelhaube', - 716: 'picket fence, paling', - 717: 'pickup, pickup truck', - 718: 'pier', - 719: 'piggy bank, penny bank', - 720: 'pill bottle', - 721: 'pillow', - 722: 'ping-pong ball', - 723: 'pinwheel', - 724: 'pirate, pirate ship', - 725: 'pitcher, ewer', - 726: "plane, carpenter's plane, woodworking plane", - 727: 'planetarium', - 728: 'plastic bag', - 729: 'plate rack', - 730: 'plow, plough', - 731: "plunger, plumber's helper", - 732: 'Polaroid camera, Polaroid Land camera', - 733: 'pole', - 734: 'police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria', - 735: 'poncho', - 736: 'pool table, billiard table, snooker table', - 737: 'pop bottle, soda bottle', - 738: 'pot, flowerpot', - 739: "potter's wheel", - 740: 'power drill', - 741: 'prayer rug, prayer mat', - 742: 'printer', - 743: 'prison, prison house', - 744: 'projectile, missile', - 745: 'projector', - 746: 'puck, hockey puck', - 747: 'punching bag, punch bag, punching ball, punchball', - 748: 'purse', - 749: 'quill, quill pen', - 750: 'quilt, comforter, comfort, puff', - 751: 'racer, race car, racing car', - 752: 'racket, racquet', - 753: 'radiator', - 754: 'radio, wireless', - 755: 'radio telescope, radio reflector', - 756: 'rain barrel', - 757: 'recreational vehicle, RV, R.V.', - 758: 'reel', - 759: 'reflex camera', - 760: 'refrigerator, icebox', - 761: 'remote control, remote', - 762: 'restaurant, eating house, eating place, eatery', - 763: 'revolver, six-gun, six-shooter', - 764: 'rifle', - 765: 'rocking chair, rocker', - 766: 'rotisserie', - 767: 'rubber eraser, rubber, pencil eraser', - 768: 'rugby ball', - 769: 'rule, ruler', - 770: 'running shoe', - 771: 'safe', - 772: 'safety pin', - 773: 'saltshaker, salt shaker', - 774: 'sandal', - 775: 'sarong', - 776: 'sax, saxophone', - 777: 'scabbard', - 778: 'scale, weighing machine', - 779: 'school bus', - 780: 'schooner', - 781: 'scoreboard', - 782: 'screen, CRT screen', - 783: 'screw', - 784: 'screwdriver', - 785: 'seat belt, seatbelt', - 786: 'sewing machine', - 787: 'shield, buckler', - 788: 'shoe shop, shoe-shop, shoe store', - 789: 'shoji', - 790: 'shopping basket', - 791: 'shopping cart', - 792: 'shovel', - 793: 'shower cap', - 794: 'shower curtain', - 795: 'ski', - 796: 'ski mask', - 797: 'sleeping bag', - 798: 'slide rule, slipstick', - 799: 'sliding door', - 800: 'slot, one-armed bandit', - 801: 'snorkel', - 802: 'snowmobile', - 803: 'snowplow, snowplough', - 804: 'soap dispenser', - 805: 'soccer ball', - 806: 'sock', - 807: 'solar dish, solar collector, solar furnace', - 808: 'sombrero', - 809: 'soup bowl', - 810: 'space bar', - 811: 'space heater', - 812: 'space shuttle', - 813: 'spatula', - 814: 'speedboat', - 815: "spider web, spider's web", - 816: 'spindle', - 817: 'sports car, sport car', - 818: 'spotlight, spot', - 819: 'stage', - 820: 'steam locomotive', - 821: 'steel arch bridge', - 822: 'steel drum', - 823: 'stethoscope', - 824: 'stole', - 825: 'stone wall', - 826: 'stopwatch, stop watch', - 827: 'stove', - 828: 'strainer', - 829: 'streetcar, tram, tramcar, trolley, trolley car', - 830: 'stretcher', - 831: 'studio couch, day bed', - 832: 'stupa, tope', - 833: 'submarine, pigboat, sub, U-boat', - 834: 'suit, suit of clothes', - 835: 'sundial', - 836: 'sunglass', - 837: 'sunglasses, dark glasses, shades', - 838: 'sunscreen, sunblock, sun blocker', - 839: 'suspension bridge', - 840: 'swab, swob, mop', - 841: 'sweatshirt', - 842: 'swimming trunks, bathing trunks', - 843: 'swing', - 844: 'switch, electric switch, electrical switch', - 845: 'syringe', - 846: 'table lamp', - 847: 'tank, army tank, armored combat vehicle, armoured combat vehicle', - 848: 'tape player', - 849: 'teapot', - 850: 'teddy, teddy bear', - 851: 'television, television system', - 852: 'tennis ball', - 853: 'thatch, thatched roof', - 854: 'theater curtain, theatre curtain', - 855: 'thimble', - 856: 'thresher, thrasher, threshing machine', - 857: 'throne', - 858: 'tile roof', - 859: 'toaster', - 860: 'tobacco shop, tobacconist shop, tobacconist', - 861: 'toilet seat', - 862: 'torch', - 863: 'totem pole', - 864: 'tow truck, tow car, wrecker', - 865: 'toyshop', - 866: 'tractor', - 867: 'trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi', - 868: 'tray', - 869: 'trench coat', - 870: 'tricycle, trike, velocipede', - 871: 'trimaran', - 872: 'tripod', - 873: 'triumphal arch', - 874: 'trolleybus, trolley coach, trackless trolley', - 875: 'trombone', - 876: 'tub, vat', - 877: 'turnstile', - 878: 'typewriter keyboard', - 879: 'umbrella', - 880: 'unicycle, monocycle', - 881: 'upright, upright piano', - 882: 'vacuum, vacuum cleaner', - 883: 'vase', - 884: 'vault', - 885: 'velvet', - 886: 'vending machine', - 887: 'vestment', - 888: 'viaduct', - 889: 'violin, fiddle', - 890: 'volleyball', - 891: 'waffle iron', - 892: 'wall clock', - 893: 'wallet, billfold, notecase, pocketbook', - 894: 'wardrobe, closet, press', - 895: 'warplane, military plane', - 896: 'washbasin, handbasin, washbowl, lavabo, wash-hand basin', - 897: 'washer, automatic washer, washing machine', - 898: 'water bottle', - 899: 'water jug', - 900: 'water tower', - 901: 'whiskey jug', - 902: 'whistle', - 903: 'wig', - 904: 'window screen', - 905: 'window shade', - 906: 'Windsor tie', - 907: 'wine bottle', - 908: 'wing', - 909: 'wok', - 910: 'wooden spoon', - 911: 'wool, woolen, woollen', - 912: 'worm fence, snake fence, snake-rail fence, Virginia fence', - 913: 'wreck', - 914: 'yawl', - 915: 'yurt', - 916: 'web site, website, internet site, site', - 917: 'comic book', - 918: 'crossword puzzle, crossword', - 919: 'street sign', - 920: 'traffic light, traffic signal, stoplight', - 921: 'book jacket, dust cover, dust jacket, dust wrapper', - 922: 'menu', - 923: 'plate', - 924: 'guacamole', - 925: 'consomme', - 926: 'hot pot, hotpot', - 927: 'trifle', - 928: 'ice cream, icecream', - 929: 'ice lolly, lolly, lollipop, popsicle', - 930: 'French loaf', - 931: 'bagel, beigel', - 932: 'pretzel', - 933: 'cheeseburger', - 934: 'hotdog, hot dog, red hot', - 935: 'mashed potato', - 936: 'head cabbage', - 937: 'broccoli', - 938: 'cauliflower', - 939: 'zucchini, courgette', - 940: 'spaghetti squash', - 941: 'acorn squash', - 942: 'butternut squash', - 943: 'cucumber, cuke', - 944: 'artichoke, globe artichoke', - 945: 'bell pepper', - 946: 'cardoon', - 947: 'mushroom', - 948: 'Granny Smith', - 949: 'strawberry', - 950: 'orange', - 951: 'lemon', - 952: 'fig', - 953: 'pineapple, ananas', - 954: 'banana', - 955: 'jackfruit, jak, jack', - 956: 'custard apple', - 957: 'pomegranate', - 958: 'hay', - 959: 'carbonara', - 960: 'chocolate sauce, chocolate syrup', - 961: 'dough', - 962: 'meat loaf, meatloaf', - 963: 'pizza, pizza pie', - 964: 'potpie', - 965: 'burrito', - 966: 'red wine', - 967: 'espresso', - 968: 'cup', - 969: 'eggnog', - 970: 'alp', - 971: 'bubble', - 972: 'cliff, drop, drop-off', - 973: 'coral reef', - 974: 'geyser', - 975: 'lakeside, lakeshore', - 976: 'promontory, headland, head, foreland', - 977: 'sandbar, sand bar', - 978: 'seashore, coast, seacoast, sea-coast', - 979: 'valley, vale', - 980: 'volcano', - 981: 'ballplayer, baseball player', - 982: 'groom, bridegroom', - 983: 'scuba diver', - 984: 'rapeseed', - 985: 'daisy', - 986: "yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum", - 987: 'corn', - 988: 'acorn', - 989: 'hip, rose hip, rosehip', - 990: 'buckeye, horse chestnut, conker', - 991: 'coral fungus', - 992: 'agaric', - 993: 'gyromitra', - 994: 'stinkhorn, carrion fungus', - 995: 'earthstar', - 996: 'hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa', - 997: 'bolete', - 998: 'ear, spike, capitulum', - 999: 'toilet tissue, toilet paper, bathroom tissue' -} diff --git a/MachineLearning_Engine/Compute/Vision/SemanticSegmentation.cs b/MachineLearning_Engine/Compute/Vision/SemanticSegmentation.cs deleted file mode 100644 index ebfc336..0000000 --- a/MachineLearning_Engine/Compute/Vision/SemanticSegmentation.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; - -namespace BH.Engine.MachineLearning.Vision -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static Tensor SegmentImage(string imagePath, bool gpu = false) - { - return new Tensor(BH.Engine.MachineLearning.Base.Compute.Invoke(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace, "SemanticSegmentation.infer", imagePath, gpu)); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Compute/Vision/SemanticSegmentation.py b/MachineLearning_Engine/Compute/Vision/SemanticSegmentation.py deleted file mode 100644 index 6f63a8b..0000000 --- a/MachineLearning_Engine/Compute/Vision/SemanticSegmentation.py +++ /dev/null @@ -1,62 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -import os -import PIL -import numpy as np -import torch -import torchvision - - -@torch.no_grad() -def infer(image_path: str, gpu: bool=False): - if not (os.path.isfile(image_path)): - raise FileNotFoundError(image_path) - - # intantiace the model - global model - if model is None: - model = torch.hub.load('pytorch/vision:v0.6.0', 'deeplabv3_resnet101', pretrained=True) - model.eval() - - # preprocess image and transform into tensor - pil_image: PIL.Image.Image = PIL.Image.open(image_path) - preprocess = torchvision.transforms.Compose([ - torchvision.transforms.ToTensor(), - torchvision.transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), - ]) - tensor_image: torch.Tensor = preprocess(pil_image).unsqueeze(0) - - # set accelerators - if gpu: - tensor_image = tensor_image.cuda() - model = model.cuda() - else: - tensor_image = tensor_image.cpu() - model = model.cpu() - - # run prediction - output = model(tensor_image).get("out") - return torch.argmax(output, dim=1).squeeze() - - -model = None diff --git a/MachineLearning_Engine/Compute/Vision/__init__.py b/MachineLearning_Engine/Compute/Vision/__init__.py deleted file mode 100644 index a1b068b..0000000 --- a/MachineLearning_Engine/Compute/Vision/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# - -from . import DetectObjects -from . import DrawDetection -from . import FindContours -from . import RecogniseObject -from . import SemanticSegmentation diff --git a/MachineLearning_Engine/Compute/__init__.py b/MachineLearning_Engine/Compute/__init__.py deleted file mode 100644 index 7824ba2..0000000 --- a/MachineLearning_Engine/Compute/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# diff --git a/MachineLearning_Engine/Convert/FromDType.cs b/MachineLearning_Engine/Convert/FromDType.cs deleted file mode 100644 index 4fb669f..0000000 --- a/MachineLearning_Engine/Convert/FromDType.cs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using Python.Runtime; -using System; - -namespace BH.Engine.MachineLearning -{ - public static partial class Convert - { - /*************************************/ - /**** Public Fields ****/ - /*************************************/ - - public static Type FromDType(this string type) - { - switch (type.ToString()) - { - case "int16": - return typeof(short); - case "int32": - return typeof(int); - case "int64": - return typeof(long); - case "float16": - return typeof(float); - case "float32": - return typeof(double); - case "float128": - return typeof(decimal); - default: - return typeof(double); - } - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Convert/ToDType.cs b/MachineLearning_Engine/Convert/ToDType.cs deleted file mode 100644 index 8f3b90c..0000000 --- a/MachineLearning_Engine/Convert/ToDType.cs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using Python.Runtime; -using System; - -namespace BH.Engine.MachineLearning -{ - public static partial class Convert - { - /*************************************/ - /**** Public Fields ****/ - /*************************************/ - - public static string ToDType(this Type type) - { - switch (type.ToString()) - { - case "System.Int16": - return "int16"; - case "System.Int32": - return "int32"; - case "System.Int64": - return "int64"; - case "System.Single": - return "float16"; - case "System.Double": - return "float32"; - case "System.Decimal": - return "float128"; - default: - return "float32"; - } - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Convert/ToList.cs b/MachineLearning_Engine/Convert/ToList.cs deleted file mode 100644 index b8ced1d..0000000 --- a/MachineLearning_Engine/Convert/ToList.cs +++ /dev/null @@ -1,115 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using BH.oM.Base.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.ComponentModel; - -namespace BH.Engine.MachineLearning -{ - public static partial class Convert - { - /***************************************************/ - /**** Public Methods ****/ - /***************************************************/ - - [Description("Convert a Tensor to a list of data.")] - [Input("tensor", "A Tensor to be converted.")] - [Output("data", "A list of data contained in the Tensor.")] - public static List ToList(this Tensor tensor) - { - // TODO: For the moment we only provide data as double or int back to C# - // It would be good to find a way to return different types - // The obstacle is that Marshal.Copy does not work on generic types - if (tensor.NumpyArray.IsIterable()) - { - if (Query.DType(tensor) == typeof(int)) - return ToListInt(tensor).Cast().ToList(); - if (Query.DType(tensor) == typeof(double)) - return ToListDouble(tensor).Cast().ToList(); - } - else - { - if (Query.DType(tensor) == typeof(int)) - return new List { ToInt(tensor) }; - if (Query.DType(tensor) == typeof(double)) - return new List { ToDouble(tensor) }; - } - return null; - } - /***************************************************/ - /***************************************************/ - /**** Private Methods ****/ - /***************************************************/ - - [Description("Convert a Tensor to a list of data.")] - [Input("tensor", "A Tensor to be converted.")] - [Output("data", "A list of data contained in the Tensor.")] - private static List ToListDouble(this Tensor tensor) - { - long ptr = tensor.NumpyArray.GetAttr("ctypes").GetAttr("data").As(); - int size = tensor.Size(); - - double[] array = new double[size]; - Marshal.Copy(new IntPtr(ptr), array, 0, array.Length); - - return array.ToList(); - } - - [Description("Convert a Tensor to a list of data.")] - [Input("tensor", "A Tensor to be converted.")] - [Output("data", "A list of data contained in the Tensor.")] - private static List ToListInt(this Tensor tensor) - { - long ptr = tensor.NumpyArray.GetAttr("ctypes").GetAttr("data").As(); - int size = tensor.Size(); - - int[] array = new int[size]; - Marshal.Copy(new IntPtr(ptr), array, 0, array.Length); - - return array.ToList(); - } - - [Description("Convert a Tensor to a list of data.")] - [Input("tensor", "A Tensor to be converted.")] - [Output("data", "A list of data contained in the Tensor.")] - private static int ToInt(this Tensor tensor) - { - return System.Convert.ToInt32(tensor.NumpyArray.ToString()); - } - - [Description("Convert a Tensor to a list of data.")] - [Input("tensor", "A Tensor to be converted.")] - [Output("data", "A list of data contained in the Tensor.")] - private static double ToDouble(this Tensor tensor) - { - return System.Convert.ToDouble(tensor.NumpyArray.ToString()); - } - /***************************************************/ - } -} - - diff --git a/MachineLearning_Engine/Convert/ToPython.cs b/MachineLearning_Engine/Convert/ToPython.cs deleted file mode 100644 index 9a4a1a4..0000000 --- a/MachineLearning_Engine/Convert/ToPython.cs +++ /dev/null @@ -1,144 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using Python.Runtime; -using System; -using System.Collections.Generic; - - -namespace BH.Engine.MachineLearning -{ - public static partial class Convert - { - /***************************************************/ - /**** Public Methods ****/ - /***************************************************/ - - public static PyObject IToPython(dynamic obj) - { - if (obj == null) - return Runtime.GetPyNone(); - - if (obj is PyObject) - return obj; - - return ToPython(obj as dynamic); - } - - /***************************************************/ - - public static PyObject ToPython(this Tensor tensor) - { - return tensor.NumpyArray; - } - - /***************************************************/ - - public static PyObject ToPython(this IEnumerable list, Type dtype = null) - { - return ToNumpyArray(list, dtype); - } - - /***************************************************/ - - public static PyObject ToPython(this IEnumerable> listOfLists, Type dtype = null) - { - return ToNumpyArray(listOfLists, dtype); - } - - /***************************************************/ - - public static PyObject ToPython(this LinearRegression model) - { - return model.SkLearnModel; - } - - /***************************************************/ - - public static PyObject ToPython(this MinMaxScaler scaler) - { - return scaler.SkLearnScaler; - } - - /***************************************************/ - - public static PyObject ToPython(this StandardScaler scaler) - { - return scaler.SkLearnScaler; - } - - /***************************************************/ - - public static PyObject ToPython(this PolynomialFeatures transformer) - { - return transformer.SkLearnTransformer; - } - - /***************************************************/ - - public static PyObject ToPython(this SupportVectorRegression regressor) - { - return regressor.SkLearnModel; - } - - /***************************************************/ - - public static PyObject ToPython(this LogisticRegression regressor) - { - return regressor.SkLearnModel; - } - - - /***************************************************/ - /**** Private Methods ****/ - /***************************************************/ - - private static PyObject ToNumpyArray(this object collection, Type dtype) - { - if (dtype == null) - dtype = typeof(double); - List args = new List { collection }; - Dictionary kwargs = new Dictionary - { - { "dtype", dtype.ToDType() } - }; - return Engine.MachineLearning.Base.Compute.InvokeNumpy("array", args, kwargs); - } - - - /***************************************************/ - /**** Fallback case ****/ - /***************************************************/ - - private static PyObject ToPython(this object obj) - { - // If no method has been found in the MachineLearning_Engine, - // Try to see if there is any convert in the Python_Engine that works - return Engine.Python.Convert.IToPython(obj); - } - - /***************************************************/ - } -} - - diff --git a/MachineLearning_Engine/Create/Tensor.cs b/MachineLearning_Engine/Create/Tensor.cs deleted file mode 100644 index c532811..0000000 --- a/MachineLearning_Engine/Create/Tensor.cs +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - - -using BH.oM.MachineLearning; -using System; -using System.Collections.Generic; - -namespace BH.Engine.MachineLearning -{ - public static partial class Create - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - public static Tensor Tensor(IEnumerable collection, Type dtype = null) - { - return new Tensor(collection.ToPython(dtype)); - } - - /*************************************/ - - public static Tensor Tensor(IEnumerable> collection, Type dtype = null) - { - return new Tensor(collection.ToPython(dtype)); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Extensions/script.py b/MachineLearning_Engine/Extensions/script.py deleted file mode 100644 index cd5cfb7..0000000 --- a/MachineLearning_Engine/Extensions/script.py +++ /dev/null @@ -1 +0,0 @@ -#Empty script to start the extensions folder till we get more items \ No newline at end of file diff --git a/MachineLearning_Engine/MachineLearning_Engine.csproj b/MachineLearning_Engine/MachineLearning_Engine.csproj index 50d6312..76fbe3d 100644 --- a/MachineLearning_Engine/MachineLearning_Engine.csproj +++ b/MachineLearning_Engine/MachineLearning_Engine.csproj @@ -1,4 +1,4 @@ - + @@ -40,25 +40,21 @@ False False - - C:\ProgramData\BHoM\Assemblies\DeepLearning_oM.dll - False - False - C:\ProgramData\BHoM\Assemblies\Geometry_oM.dll False False - - False - ..\libs\Python.Runtime.dll - C:\ProgramData\BHoM\Assemblies\Python_Engine.dll False False + + C:\ProgramData\BHoM\Assemblies\Python_oM.dll + False + False + C:\ProgramData\BHoM\Assemblies\Reflection_Engine.dll False @@ -76,45 +72,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - + @@ -123,50 +83,37 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + - + + + - - xcopy "$(TargetDir)$(TargetFileName)" "C:\\ProgramData\\BHoM\\Assemblies" /Y -xcopy "$(SolutionDir)*.py" "C:\\ProgramData\\BHoM\\Extensions\\Python\\src\\$(SolutionName)\" /Y /I /S /F -xcopy "$(SolutionDir)requirements.txt" "C:\\ProgramData\\BHoM\\Extensions\\Python\\src\\" /Y /I /S /F -xcopy /E /Y /I "$(ProjectDir)Extensions" "C:\\ProgramData\\BHoM\\Extensions\MachineLearning" + + xcopy "$(TargetDir)$(TargetFileName)" "C:\\ProgramData\\BHoM\\Assemblies" /Y + + :: create infrastructure necessary to support Python environments + if not exist "C:\ProgramData\BHoM\Extensions\PythonEnvironments" mkdir "C:\ProgramData\BHoM\Extensions\PythonEnvironments" + if not exist "C:\ProgramData\BHoM\Extensions\PythonCode" mkdir "C:\ProgramData\BHoM\Extensions\PythonCode" + + :: remove any old versions within target directory for current toolkits Python code + if exist "C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)" rmdir "C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)" /S /Q + + :: move Python code over to toolkit extensions folder, redirecting output to temp log file to silence it + robocopy "$(ProjectDir)Python" "C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)" /s /purge /xf "*.pyc" "*.ipynb" /xd "\__pycache__\" > output.log + + :: remove temporary log file + del output.log + diff --git a/MachineLearning_Engine/Modify/AsType.cs b/MachineLearning_Engine/Modify/AsType.cs deleted file mode 100644 index 08db8c4..0000000 --- a/MachineLearning_Engine/Modify/AsType.cs +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using Python.Runtime; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace BH.Engine.MachineLearning -{ - public static partial class Modify - { - /***************************************************/ - /**** Public Methods ****/ - /***************************************************/ - - public static Tensor AsType(this Tensor tensor, string dtype) - { - return new Tensor(Base.Compute.InvokeNumpy("astype", tensor.ToPython(), dtype)); - } - - /***************************************************/ - - public static Tensor AsType(this Tensor tensor, Type dtype) - { - return new Tensor(Base.Compute.InvokeNumpy("astype", tensor.ToPython(), dtype.ToDType())); - } - - /***************************************************/ - } -} - - diff --git a/MachineLearning_Engine/Python/README.md b/MachineLearning_Engine/Python/README.md new file mode 100644 index 0000000..8b28368 --- /dev/null +++ b/MachineLearning_Engine/Python/README.md @@ -0,0 +1,3 @@ +# MeachineLearning_Toolkit + +The code contained here is intended to be used in conjunction with the MachineLEarning_Toolkit, as part of a wider [BHoM](https://bhom.xyz/) installation. \ No newline at end of file diff --git a/MachineLearning_Engine/Python/requirements.txt b/MachineLearning_Engine/Python/requirements.txt new file mode 100644 index 0000000..2ab0c91 --- /dev/null +++ b/MachineLearning_Engine/Python/requirements.txt @@ -0,0 +1,6 @@ +keras==2.9.0 +pandas==1.3.5 +scikit-learn==1.0.2 +scipy==1.7.3 +tensorflow==2.9.1 +torch==1.12.0 \ No newline at end of file diff --git a/MachineLearning_Engine/Python/setup.py b/MachineLearning_Engine/Python/setup.py new file mode 100644 index 0000000..81d185e --- /dev/null +++ b/MachineLearning_Engine/Python/setup.py @@ -0,0 +1,20 @@ +from setuptools import setup, find_packages +import pathlib + +here = pathlib.Path(__file__).parent.resolve() +long_description = (here / "README.md").read_text(encoding="utf-8") +requirements = [i.strip() for i in (here / "requirements.txt").read_text(encoding="utf-8-sig").splitlines()] + +# TODO - populate values here with values from global config instead +setup( + name="machinelearning_toolkit", + author="BHoM", + author_email="bhombot@burohappold.com", + description="A Python library that enables Python to be used within BHoM workflows", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/BHoM/MachineLearning_Toolkit", + package_dir={"": "src"}, + packages=find_packages(where="src", exclude=['tests']), + install_requires=requirements, +) diff --git a/MachineLearning_Engine/Python/src/__init__.py b/MachineLearning_Engine/Python/src/__init__.py new file mode 100644 index 0000000..83b87df --- /dev/null +++ b/MachineLearning_Engine/Python/src/__init__.py @@ -0,0 +1,20 @@ +from setuptools import setup, find_packages +import pathlib + +here = pathlib.Path(__file__).parent.resolve() +long_description = (here / "README.md").read_text(encoding="utf-8") +requirements = [i.strip() for i in (here / "requirements.txt").read_text(encoding="utf-8-sig").splitlines()] + +# TODO - populate values here with values from global config instead +setup( + name="cfd_toolkit", + author="BHoM", + author_email="bhombot@burohappold.com", + description="A Python library that enables Python to be used within BHoM workflows", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/BuroHappoldEngineering/CFD_Toolkit", + package_dir={"": "src"}, + packages=find_packages(where="src", exclude=['tests']), + install_requires=requirements, +) diff --git a/MachineLearning_Engine/Python/src/machinelearning_toolkit/__init__.py b/MachineLearning_Engine/Python/src/machinelearning_toolkit/__init__.py new file mode 100644 index 0000000..83b87df --- /dev/null +++ b/MachineLearning_Engine/Python/src/machinelearning_toolkit/__init__.py @@ -0,0 +1,20 @@ +from setuptools import setup, find_packages +import pathlib + +here = pathlib.Path(__file__).parent.resolve() +long_description = (here / "README.md").read_text(encoding="utf-8") +requirements = [i.strip() for i in (here / "requirements.txt").read_text(encoding="utf-8-sig").splitlines()] + +# TODO - populate values here with values from global config instead +setup( + name="cfd_toolkit", + author="BHoM", + author_email="bhombot@burohappold.com", + description="A Python library that enables Python to be used within BHoM workflows", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/BuroHappoldEngineering/CFD_Toolkit", + package_dir={"": "src"}, + packages=find_packages(where="src", exclude=['tests']), + install_requires=requirements, +) diff --git a/MachineLearning_Engine/Query/DType.cs b/MachineLearning_Engine/Query/DType.cs deleted file mode 100644 index 39f12ed..0000000 --- a/MachineLearning_Engine/Query/DType.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.Engine.Python; -using BH.oM.MachineLearning; -using Python.Runtime; -using System; - -namespace BH.Engine.MachineLearning -{ - public static partial class Query - { - /*************************************/ - /**** Public Fields ****/ - /*************************************/ - - public static Type DType(this Tensor tensor) - { - string dtype = tensor.NumpyArray?.GetAttr("dtype")?.GetAttr("name")?.FromPython(); - return dtype?.FromDType(); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Query/GetAttribute.cs b/MachineLearning_Engine/Query/GetAttribute.cs deleted file mode 100644 index 2990c12..0000000 --- a/MachineLearning_Engine/Query/GetAttribute.cs +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using BH.Engine.Python; -using System.Collections.Generic; - -namespace BH.Engine.MachineLearning -{ - public static partial class Query - { - /*************************************/ - /**** Public Fields ****/ - /*************************************/ - - public static object GetAttribute(this Tensor tensor, string attribute) - { - return tensor.NumpyArray.GetAttr(attribute).IFromPython(); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Query/Import.cs b/MachineLearning_Engine/Query/Import.cs deleted file mode 100644 index 46f2703..0000000 --- a/MachineLearning_Engine/Query/Import.cs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using Python.Runtime; -using System.Windows.Forms; -using System; -using System.Diagnostics; - -namespace BH.Engine.MachineLearning -{ - public static partial class Query - { - /*************************************/ - /**** Public Fields ****/ - /*************************************/ - - public static PyObject Import(string module) - { - bool moduleInstalled = Python.Query.IsModuleInstalled(module); - if (moduleInstalled) - return Python.Query.Import(module); - - // if module is not installed ask for automatic installation - string installMessage = $"Cannot import module {module}, because the MachineLearning_Toolkit is not installed. Do you want to install the module?"; - DialogResult confirmResult = MessageBox.Show(installMessage, "BHoM package manager", MessageBoxButtons.YesNoCancel); - - if (confirmResult == DialogResult.Yes) - { - if (!Python.Query.IsModuleInstalled("MachineLearning_Engine")) - { - // InstallMachineLearningToolkit also installs python if it is not found - bool mlToolkitSuccess = Base.Compute.InstallMachineLearningToolkit(true).Item1; - } - } - else - { - string errorMessage = $"Cannot import module {module} because no valid version of Python for the BHoM has been found.\n" + - "Try installing Python and the MachineLearning_Toolkit using the Compute.InstallMachineLearningToolkit component.\n" + - "If the installation process fails, pleae consider reporting a bug at " + - "https://github.com/BHoM/MachineLearning_Toolkit/issues/new?labels=type%3Abug&template=00_bug.md"; - throw new Exception(errorMessage); - } - - return Python.Query.Import(module); - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Query/Shape.cs b/MachineLearning_Engine/Query/Shape.cs deleted file mode 100644 index 462f729..0000000 --- a/MachineLearning_Engine/Query/Shape.cs +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.MachineLearning; -using BH.Engine.Python; -using System.Collections.Generic; - -namespace BH.Engine.MachineLearning -{ - public static partial class Query - { - /*************************************/ - /**** Public Fields ****/ - /*************************************/ - - public static List Shape(this Tensor tensor) - { - return tensor.NumpyArray.GetAttr("shape").IFromPython() as List; - } - - /*************************************/ - } -} - - diff --git a/MachineLearning_Engine/Query/Size.cs b/MachineLearning_Engine/Query/ToolkitName.cs similarity index 79% rename from MachineLearning_Engine/Query/Size.cs rename to MachineLearning_Engine/Query/ToolkitName.cs index bc633e3..8a4c1c8 100644 --- a/MachineLearning_Engine/Query/Size.cs +++ b/MachineLearning_Engine/Query/ToolkitName.cs @@ -1,4 +1,4 @@ -/* +/* * This file is part of the Buildings and Habitats object Model (BHoM) * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. * @@ -20,24 +20,20 @@ * along with this code. If not, see . */ -using BH.oM.MachineLearning; -using BH.Engine.Python; + +using BH.oM.Base.Attributes; + +using System.ComponentModel; namespace BH.Engine.MachineLearning { public static partial class Query { - /*************************************/ - /**** Public Fields ****/ - /*************************************/ - - public static int Size(this Tensor tensor) + [Description("Get the name of the current toolkit.")] + [Output("name", "The name of the current toolkit.")] + public static string ToolkitName() { - return (Base.Compute.InvokeNumpy("size", tensor.ToPython())).FromPython(); + return "MachineLearning_Toolkit"; } - - /*************************************/ } } - - diff --git a/MachineLearning_Engine/Versioning_53.json b/MachineLearning_Engine/Versioning_53.json new file mode 100644 index 0000000..b857e30 --- /dev/null +++ b/MachineLearning_Engine/Versioning_53.json @@ -0,0 +1,86 @@ +{ + "Namespace": { + "ToNew": { + }, + "ToOld": { + } + }, + "Type": { + "ToNew": { + + }, + "ToOld": { + } + }, + "Property": { + "ToNew": { + }, + "ToOld": { + } + }, + "MessageForDeleted": { + "BH.Engine.MachineLearning.Audio.Compute.PlayAudio(BH.oM.MachineLearning.Tensor, System.Int32, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Audio.Compute.RecogniseSpeech(System.String, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Audio.Compute.SynthesiseSpeech(System.String, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Base.Compute.Invoke(System.String, System.String, System.Collections.Generic.Dictionary)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Base.Compute.Invoke(System.String, System.String, System.Object[])": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Base.Compute.InvokeNumpy(System.String, System.Collections.Generic.IEnumerable, System.Collections.Generic.Dictionary)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Base.Compute.InvokeNumpy(System.String, System.Object[])": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Charts.Compute.PlotDiurnal(System.Collections.Generic.List, System.String, System.String, System.Collections.Generic.List, System.String, System.String, System.String, System.String, System.Boolean, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Charts.Compute.PlotFrequency(System.Collections.Generic.List, System.String, System.String, System.String, System.Collections.Generic.List, System.Int32, System.String, System.String, System.Boolean, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Charts.Compute.PlotHeatmap(System.Collections.Generic.List, System.String, System.String, System.String, System.Collections.Generic.List, System.String, System.String, System.Boolean, System.Boolean, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Charts.Compute.PlotImage(BH.oM.MachineLearning.Tensor, System.Int32, System.Int32, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Charts.Compute.PlotImage(BH.oM.MachineLearning.Vision.Image, System.Int32, System.Int32, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Charts.Compute.PlotUTCI(System.Collections.Generic.List, System.String, System.Boolean, System.String, System.String, System.Boolean, System.Boolean, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.FromDType(System.String)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.IToPython(System.Object)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToDType(System.Type)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToList(BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToPython(BH.oM.MachineLearning.LinearRegression)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToPython(System.Collections.Generic.IEnumerable, System.Type)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToPython(System.Collections.Generic.IEnumerable>, System.Type)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToPython(BH.oM.MachineLearning.LogisticRegression)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToPython(BH.oM.MachineLearning.MinMaxScaler)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToPython(BH.oM.MachineLearning.PolynomialFeatures)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToPython(BH.oM.MachineLearning.StandardScaler)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToPython(BH.oM.MachineLearning.SupportVectorRegression)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Convert.ToPython(BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Create.Tensor(System.Collections.Generic.IEnumerable>, System.Type)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Create.Tensor(System.Collections.Generic.IEnumerable, System.Type)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Datasets.Compute.LoadCsv(System.String, System.String, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Modify.AsType(BH.oM.MachineLearning.Tensor, System.String)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Modify.AsType(BH.oM.MachineLearning.Tensor, System.Type)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Preprocessing.Compute.Infer(BH.oM.MachineLearning.MinMaxScaler, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Preprocessing.Compute.Infer(BH.oM.MachineLearning.PolynomialFeatures, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Preprocessing.Compute.Infer(BH.oM.MachineLearning.StandardScaler, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Preprocessing.Compute.InferInverse(BH.oM.MachineLearning.MinMaxScaler, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Preprocessing.Compute.InferInverse(BH.oM.MachineLearning.StandardScaler, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Preprocessing.Compute.MinMaxScaler(BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Preprocessing.Compute.PolynomialFeatures(System.Int32, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Preprocessing.Compute.StandardScaler(BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Query.DType(BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Query.GetAttribute(BH.oM.MachineLearning.Tensor, System.String)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Query.Import(System.String)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Query.Shape(BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Query.Size(BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Structured.Compute.Coefficients(BH.oM.MachineLearning.IRegressionModel)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Structured.Compute.Infer(BH.oM.MachineLearning.LinearRegression, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Structured.Compute.Infer(BH.oM.MachineLearning.LogisticRegression, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Structured.Compute.Infer(BH.oM.MachineLearning.SupportVectorRegression, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Structured.Compute.LinearRegression(BH.oM.MachineLearning.Tensor, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Structured.Compute.LogisticRegression(BH.oM.MachineLearning.Tensor, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Structured.Compute.Score(BH.oM.MachineLearning.IRegressionModel, BH.oM.MachineLearning.Tensor, BH.oM.MachineLearning.Tensor)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Structured.Compute.SupportVectorRegression(BH.oM.MachineLearning.Tensor, BH.oM.MachineLearning.Tensor, System.String, System.Int32, System.Double)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Text.Compute.Answer(System.String, System.String)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Text.Compute.SentimentAnalysis(System.String)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Text.Compute.Summarise(System.String)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Vision.Compute.DetectObjects(System.String, System.Boolean, System.Double)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Vision.Compute.DrawDetection(System.String, Python.Runtime.PyObject, System.Double)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Vision.Compute.FindContours(BH.oM.MachineLearning.Tensor, System.Int32)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Vision.Compute.RecogniseObject(System.String, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.Engine.MachineLearning.Vision.Compute.SegmentImage(System.String, System.Boolean)": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues." + + }, + "MessageForNoUpgrade": { + } +} \ No newline at end of file diff --git a/MachineLearning_Engine/__init__.py b/MachineLearning_Engine/__init__.py deleted file mode 100644 index 7824ba2..0000000 --- a/MachineLearning_Engine/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -# -# This file is part of the Buildings and Habitats object Model (BHoM) -# Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. -# -# Each contributor holds copyright over their respective contributions. -# The project versioning (Git) records all such contribution source information. -# -# -# The BHoM is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3.0 of the License, or -# (at your option) any later version. -# -# The BHoM is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this code. If not, see . -# diff --git a/MachineLearning_Toolkit.sln b/MachineLearning_Toolkit.sln index fa286b0..5a93455 100644 --- a/MachineLearning_Toolkit.sln +++ b/MachineLearning_Toolkit.sln @@ -1,18 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30523.141 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32014.148 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineLearning_Engine", "MachineLearning_Engine\MachineLearning_Engine.csproj", "{61DCF1F4-D6DD-4512-8905-58D1868DA9DB}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineLearning_oM", "MachineLearning_oM\MachineLearning_oM.csproj", "{C3F87EBB-3F93-4069-A17F-D55868056ED2}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{82F38474-BA80-4CAA-991C-B787A8D9186E}" - ProjectSection(SolutionItems) = preProject - requirements.txt = requirements.txt - setup.py = setup.py - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/MachineLearning_oM/IRegressionModel.cs b/MachineLearning_oM/IRegressionModel.cs deleted file mode 100644 index 65bcc84..0000000 --- a/MachineLearning_oM/IRegressionModel.cs +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using Python.Runtime; - -namespace BH.oM.MachineLearning -{ - public interface IRegressionModel - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - PyObject SkLearnModel { get; } - } -} - - diff --git a/MachineLearning_oM/IScaler.cs b/MachineLearning_oM/IScaler.cs deleted file mode 100644 index 05dc577..0000000 --- a/MachineLearning_oM/IScaler.cs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -namespace BH.oM.MachineLearning -{ - public interface IScaler - { - } -} - - diff --git a/MachineLearning_oM/ITransformer.cs b/MachineLearning_oM/ITransformer.cs deleted file mode 100644 index ee2015b..0000000 --- a/MachineLearning_oM/ITransformer.cs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -namespace BH.oM.MachineLearning -{ - public interface ITransformer - { - } -} - - diff --git a/MachineLearning_oM/LinearRegression.cs b/MachineLearning_oM/LinearRegression.cs deleted file mode 100644 index ed80210..0000000 --- a/MachineLearning_oM/LinearRegression.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using Python.Runtime; - -namespace BH.oM.MachineLearning -{ - public class LinearRegression : BHoMObject, IRegressionModel, IImmutable - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual PyObject SkLearnModel { get; } = null; - - - /***************************************************/ - /**** Constructors ****/ - /***************************************************/ - - public LinearRegression(PyObject skLearnModel) - { - SkLearnModel = skLearnModel; - } - - - /***************************************************/ - } -} - - diff --git a/MachineLearning_oM/LogisticRegression.cs b/MachineLearning_oM/LogisticRegression.cs deleted file mode 100644 index 64026df..0000000 --- a/MachineLearning_oM/LogisticRegression.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using Python.Runtime; - -namespace BH.oM.MachineLearning -{ - public class LogisticRegression : BHoMObject, IRegressionModel, IImmutable - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual PyObject SkLearnModel { get; } = null; - - - /***************************************************/ - /**** Constructors ****/ - /***************************************************/ - - public LogisticRegression(PyObject skLearnModel) - { - SkLearnModel = skLearnModel; - } - - - /***************************************************/ - } -} - - diff --git a/MachineLearning_oM/MachineLearning_oM.csproj b/MachineLearning_oM/MachineLearning_oM.csproj index 1dacf1b..8d306f0 100644 --- a/MachineLearning_oM/MachineLearning_oM.csproj +++ b/MachineLearning_oM/MachineLearning_oM.csproj @@ -41,11 +41,6 @@ False False - - - False - ..\libs\Python.Runtime.dll - @@ -56,19 +51,10 @@ - - - - - - - - - - - - + + + diff --git a/MachineLearning_oM/MinMaxScaler.cs b/MachineLearning_oM/MinMaxScaler.cs deleted file mode 100644 index 6644b28..0000000 --- a/MachineLearning_oM/MinMaxScaler.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using Python.Runtime; - -namespace BH.oM.MachineLearning -{ - public class MinMaxScaler : BHoMObject, IScaler, IImmutable - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual PyObject SkLearnScaler { get; } = null; - - - /***************************************************/ - /**** Constructors ****/ - /***************************************************/ - - public MinMaxScaler(PyObject skLearnModel) - { - SkLearnScaler = skLearnModel; - } - - - /***************************************************/ - } -} - - diff --git a/MachineLearning_oM/PolynomialFeatures.cs b/MachineLearning_oM/PolynomialFeatures.cs deleted file mode 100644 index ecddd3c..0000000 --- a/MachineLearning_oM/PolynomialFeatures.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using Python.Runtime; - -namespace BH.oM.MachineLearning -{ - public class PolynomialFeatures : BHoMObject, ITransformer, IImmutable - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual PyObject SkLearnTransformer { get; } = null; - - - /***************************************************/ - /**** Constructors ****/ - /***************************************************/ - - public PolynomialFeatures(PyObject skLearnTransformer) - { - SkLearnTransformer = skLearnTransformer; - } - - - /***************************************************/ - } -} - - diff --git a/MachineLearning_oM/StandardScaler.cs b/MachineLearning_oM/StandardScaler.cs deleted file mode 100644 index 345096d..0000000 --- a/MachineLearning_oM/StandardScaler.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using Python.Runtime; - -namespace BH.oM.MachineLearning -{ - public class StandardScaler : BHoMObject, IScaler, IImmutable - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual PyObject SkLearnScaler { get; } = null; - - - /***************************************************/ - /**** Constructors ****/ - /***************************************************/ - - public StandardScaler(PyObject skLearnScaler) - { - SkLearnScaler = skLearnScaler; - } - - - /***************************************************/ - } -} - - diff --git a/MachineLearning_oM/SupportVectorRegression.cs b/MachineLearning_oM/SupportVectorRegression.cs deleted file mode 100644 index 09a47a3..0000000 --- a/MachineLearning_oM/SupportVectorRegression.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using Python.Runtime; - -namespace BH.oM.MachineLearning -{ - public class SupportVectorRegression : BHoMObject, IRegressionModel, IImmutable - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual PyObject SkLearnModel { get; } = null; - - - /***************************************************/ - /**** Constructors ****/ - /***************************************************/ - - public SupportVectorRegression(PyObject skLearnModel) - { - SkLearnModel = skLearnModel; - } - - - /***************************************************/ - } -} - - diff --git a/MachineLearning_oM/Tensor.cs b/MachineLearning_oM/Tensor.cs deleted file mode 100644 index 9a1b94b..0000000 --- a/MachineLearning_oM/Tensor.cs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using Python.Runtime; -using System; - -namespace BH.oM.MachineLearning -{ - public class Tensor : BHoMObject, IImmutable - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual PyObject NumpyArray { get; } = null; - - - /***************************************************/ - /**** Constructor ****/ - /***************************************************/ - - public Tensor(PyObject numpyArray) - { - NumpyArray = numpyArray; - } - - - /***************************************************/ - /**** Constructor ****/ - /***************************************************/ - - public override string ToString() - { - return NumpyArray.ToString(); - } - - /***************************************************/ - } -} - - diff --git a/MachineLearning_oM/Versioning_53.json b/MachineLearning_oM/Versioning_53.json new file mode 100644 index 0000000..b331b87 --- /dev/null +++ b/MachineLearning_oM/Versioning_53.json @@ -0,0 +1,29 @@ +{ + "Namespace": { + "ToNew": {}, + "ToOld": {} + }, + "Type": { + "ToNew": {}, + "ToOld": {} + }, + "Property": { + "ToNew": {}, + "ToOld": {} + }, + "MessageForDeleted": { + "BH.oM.MachineLearning.IRegressionModel": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.IScaler": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.ITransformer": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.LinearRegression": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.LogisticRegression": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.MinMaxScaler": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.PolynomialFeatures": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.StandardScaler": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.SupportVectorRegression": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.Tensor": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.Vision.DetectionResults": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues.", + "BH.oM.MachineLearning.Vision.Image": "This method was originally included in BHoM to enable the use of Python.NET. This workflow has been removed in favour of use of Python virtual environments managed via BHoM in order to simplify the passing of data between the two languages. If further assistance is needed, please raise an issue on https://github.com/BHoM/MachineLearning_Toolkit/issues." + }, + "MessageForNoUpgrade": {} +} diff --git a/MachineLearning_oM/Vision/DetectionResults.cs b/MachineLearning_oM/Vision/DetectionResults.cs deleted file mode 100644 index 65176c6..0000000 --- a/MachineLearning_oM/Vision/DetectionResults.cs +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Geometry; -using System.Collections.Generic; - -namespace BH.oM.MachineLearning.Vision -{ - public class DetectionResults - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual List Boxes { get; set; } = new List(); - - public virtual List Categories { get; set; } = new List(); - - public virtual List Scores { get; set; } = new List(); - - /***************************************************/ - } -} - - diff --git a/MachineLearning_oM/Vision/Image.cs b/MachineLearning_oM/Vision/Image.cs deleted file mode 100644 index a40d1ef..0000000 --- a/MachineLearning_oM/Vision/Image.cs +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using BH.oM.Geometry; -using Python.Runtime; -using System.Collections.Generic; - -namespace BH.oM.MachineLearning.Vision -{ - public class Image : BHoMObject, IImmutable - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual PyObject Data { get; } = null; - - - /***************************************************/ - /**** Constructors ****/ - /***************************************************/ - - public Image(PyObject data) - { - Data = data; - } - - - /***************************************************/ - } -} - - diff --git a/README.md b/README.md index 6330f96..9bfbd91 100644 --- a/README.md +++ b/README.md @@ -1,63 +1 @@ -[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) -## Install me -To install the MachineLearning_Toolkit: -1. Compile: - 1. [BHoM](https://github.com/BHoM/BHoM) - 1. [BHoM_Engine](https://github.com/BHoM/BHoM_Engine) - 1. [BHoM_Adapter](https://github.com/BHoM/BHoM_Adapter) - 1. [BHoM_UI](https://github.com/BHoM/BHoM_UI) - 1. [Rhinoceros_Toolkit](https://github.com/BHoM/Rhinoceros_Toolkit) - 1. [Grasshopper_Toolkit](https://github.com/BHoM/Grasshopper_Toolkit) - 1. [Python_Toolkit](https://github.com/BHoM/Python_Toolkit) - 1. MachineLearning_Toolkit (this repo) -1. Open a UI of your choice (e.g. Grasshopper) -1. Run the `BH.Engine.Python.Compute.InstallPythonToolkit` component and wait for the installation to finish. -1. The installation has succeeded if the install packages include: - - Python 3.7 - - jupyter - - matplotlib - - Python_Toolkit -1. Restart your UI - if using Grasshopper, restart Rhinoceros and Grasshopper -1. Reopen the UI and now install the python bindings of the MachineLearning_Toolkit by running - the `BH.Engine.MachineLearning.Compute.InstallMachineLearningToolkit` component -1. Restart your UI - -Note that the installation will take a while - around 15 minutes. - -## Notes for developers -- The python source files used by Python are stored in `C:\ProgramData\BHoM\Extensions\Python\src`. This folder is populated by the Visual Studio post-build events, which copy all the `*.py` files in the Toolkit into the destination folder. -- If you update a python file in your repo, to update the BHoM you just need to recompile the solution - this will copy the relevant files as described above. -- If you update a `.cs` file, you need to recompile the solution as usual. -- The component `InstallMachineLearningToolkit` installs the additional packages required by the python bindings of the BHoM. You will seldom use this method - usually only the first time. - -Also, take a look at the [Python_Toolkit](https://github.com/BHoM/Python_Toolkit) for additional information: - - -## Adding a new algorithm using python -If you want to add a new algorithm (e.g. KMeans) that requires python, below are the required steps to enable automatic deployment of the mehtod. -1. Add an oM object that stores the model - usually ML algorithms are parameterised functions, whose parameters are stored in a _model_. - The object must be `IImmutable` and usually contains only one field that is a `PyObject`. -1. Add a `Engine.Convert.ToPython` method that takes the new object in and returns a `PyObject` -1. Add your algorithm in the `Engine.Compute` class. The algorithm usually contains three main methods: `Create`, which creates or loads the model; `Fit` that runs the learning routine; and `Infer`, which allows inference on a learnt model. -1. Note that all the python files must be contained into a `youralgorithmname.py` file, in the `Compute` folder, in order for it to work. - - -## Building the BHoM and the Toolkits from Source ## -You will need the following to build BHoM: - -- Microsoft Visual Studio 2013 or higher -- Microsoft .NET Framework 4.0 and above (included with Visual Studio 2013) -- Note that there are no software - specific dependencies (only operating system relevant), this is specific: BHoM is a software agnostic object model. - - -## Want to contribute? ## - -BHoM is an open-source project and would be nothing without its community. Take a look at our contributing guidelines and tips [here](https://github.com/BHoM/BHoM/blob/master/CONTRIBUTING.md). - - -## Licence ## - -BHoM is free software licenced under GNU Lesser General Public Licence - [https://www.gnu.org/licenses/lgpl-3.0.html](https://www.gnu.org/licenses/lgpl-3.0.html) -Each contributor holds copyright over their respective contributions. -The project versioning (Git) records all such contribution source information. -See [LICENSE](https://github.com/BHoM/BHoM/blob/master/LICENSE) and [COPYRIGHT_HEADER](https://github.com/BHoM/BHoM/blob/master/COPYRIGHT_HEADER.txt). +# MachineLearning_Toolkit diff --git a/libs/Python.Runtime.dll b/libs/Python.Runtime.dll deleted file mode 100644 index cb7184e..0000000 Binary files a/libs/Python.Runtime.dll and /dev/null differ