97

CodeProject SenseAI Server: AI the easy way. - CodeProject

 2 years ago
source link: https://www.codeproject.com/Articles/5322557/CodeProject-SenseAI-Server-AI-the-easy-way
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The What and the Why

The 'What' is simple: a locally installed, self-hosted, fast, free and Open Source Artificial Intelligence server that provides AI functionality for your apps. Install SenseAI and you have an AI server. Done.

The 'Why'

  • AI programming is something every single developer should be aware of

    We wanted a fun project we could use to help teach developers and get them involved in AI. We'll be using SenseAI as a focus for articles and exploration to make it fun and painless to learn AI programming

    We want your contributions!
  • AI coding examples have too many moving parts

    You need to install packages and languages and extensions to tools, and then updates and libraries (but version X, not version Y) and then you have to configure paths and...Oh, you want to run on Windows not Linux? In that case you need to... It's all too hard. There was much yelling at CodeProject.

    SenseAI includes everything you need in a single installer. SenseAI also provides an installation script that will setup your dev environment and get you debugging within a couple of clicks.
  • AI solutions often require the use of cloud services

    If you trust the cloud provider, or understand the billing structure, or can be assured you aren't sending sensitive data or won't go over the free tier this is fine. If you have a webcam inside your house, or can't work out how much AWS will charge, it's not so OK

    SenseAI can be installed locally. Your machine, your network, no data needs to leave your device.

Cut to the chase: how do I play with it?

1: Running and playing with the features

  1. Download the latest version, install, and launch the shortcut to the server's dashboard on your desktop.
  2. On the dashboard, at the bottom, is a link to the demo playground. Open that and play!

2: Running and debugging the code

  1. Clone the CodeProject SenseAI repository.
  2. Make sure you have Visual Studio Code or Visual Studio 2019+ installed.
  3. Run the setup script in /Installers/Dev
  4. Debug the front-end server application (see notes below, but it's easy)

How do I use it in my application?

Here's an example of using the API for scene detection using a simple JavaScript call:

Copy Code
<html>
<body>
Detect the scene in this file: <input id="image" type="file" />
<input type="button" value="Detect Scene" onclick="detectScene(image)" />

<script>
function detectScene(fileChooser) {
    var formData = new FormData();
    formData.append('image', fileChooser.files[0]);

    fetch('http://localhost:5000/v1/vision/detect/scene', {
        method: "POST",
        body: formData
    })
    .then(response => {
        if (response.ok) response.json().then(data => {
            console.log(`Scene is ${data.label}, ${data.confidence} confidence`)
        });
    });
}
</script>
</body>
</html>

You can include the CodeProject SenseAI installer (or just a link to the latest version of the installer) in your own apps and installers and voila, you have an AI enabled app.

What does it include?

CodeProject SenseAI includes

  • A HTTP REST API Server. The server listens for requests from other apps, passes them to the backend analysis services for processing, and then passes the results back to the caller. It runs as a simple self contained web service on your device.
  • Backend Analysis services. The brains of the operation is in the analysis services sitting behind the front end API. All processing of data is done on the current machine. No calls to the cloud and no data leaving the device.
  • The Source Code, naturally.

What can it do?

CodeProject SenseAI can currently

  • Detect objects in images
  • Detect faces in images
  • Detect the type of scene represented in an image
  • Recognize faces that have been registered with the service

We will be constantly expanding the feature list.

Our Goals

  • To promote AI development and inspire the AI developer community to dive in and have a go. Artificial Intelligence is a huge paradigm change in the industry and all developers owe it to themselves to experiment in and familiarize themselves with the technology. CodeProject SenseAI was built as a learning tool, a demonstration, and a library and service that can be used out of the box.
  • To make AI development easy. It's not that AI development is that hard. It's that there are so, so many options. Our architecture is designed to allow any AI implementation to find a home in our system, and for our service to be callable from any language.
  • To focus on core use-cases. We're deliberately not a solution for everyone. Instead we're a solution for common day-to-day needs. We will be adding dozens of modules and scores of AI capabilities to our system, but our goal is always clarity and simplicity over a 100% solution.
  • To tap the expertise of the Developer Community. We're not experts but we know a developer or two out there who are. The true power of CodeProject SenseAI comes from the contributions and improvements from our AI community.

How to install CodeProject.SenseAI

Supported Environments

This is a Beta release and so support is constrained solely to Windows 10+, 64bit, using CPU acceleration. Future releases will include other Operating Systems as well as GPU support.

Installing CodeProject.SenseAI

To install CodeProject.SenseAI as a standalone service ready for integration with applications such as HomeAssist or BlueIris, download the latest installation package.

Double click the installer. This will install the server as a Windows Service. SenseAI Server and the backend analysis services will now be running, and will automatically restart each time your machine is restarted.

To explore CodeProject.SenseAI open the /demos/Javascript/ folder and double click on the Vision.html page. The server will, of course, need to be running for this test application to function. Sample images can be found in the TestData folder under the demos folder

Setting up the development environment

If you wish to debug or make enhancements to the code then you should install:

  1. Visual Studio Code or Visual Studio 2019+VS Code is available on Windows, macOS and Linux. Visual Studio is available on Windows and macOS. We've tested against both, but not against other IDEs at this point

  2. Python. You may add Python tool support either via the Visual Studio Installer, through Visual Code Extensions, or by downloading python directly. However, this is not needed since Python will be installed automatically as part of the development environment setup script.

  3. .NET 6 SDK Download the .NET SDK 6 here.

  4. For the (Optional) WIX installers we do all our work within Visual Studio. For this you will need to

    1. Go to Extensions -> Manage Extensions, search for Wix and install Wix toolset Visual Studio 2019 Extension

    2. Download the Wix Toolset Build tools by heading to the download page, clicking the download link, and then download the .exe installer from the GitHub page you're directed to. The current version is 3.11.

    3. Ensure you have .NET 3.5.1 (that's not a typo) installed. See the /Installers/Windows/.NET 3.5.1 directory for a link to the installer download

      You do not need to install support for creating the installers for general development.

Platform Specific

  1. For Windows simply ensure the .NET 6 SDK is installed.

  2. For Ubuntu 21.10, 21.04 (inc. LTS), 18.04 (LTS) first install the .NET 6 packages

    Shell
    Copy Code
    wget https://packages.microsoft.com/config/ubuntu/<version>/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
    rm packages-microsoft-prod.deb

    where is the version of Ubuntu (use lbs_release -d to find your current version). Note that for Ubuntu 21.10 you should use 21.04 due to the 21.10 packages not yet being available.

    To install the .NET 6 SDK on Ubuntu run

    Shell
    Copy Code
    sudo apt-get update; \
    sudo apt-get install -y apt-transport-https && \
    sudo apt-get update && \
    sudo apt-get install -y dotnet-sdk-6.0 

    See Install the .NET SDK or the .NET Runtime on Ubuntu for more information.

    You may be prompted to instead wget and unzip if they aren't already on your system.

  3. For macOS just use the standalone .NET SDK installers, and for setting up the dev environment ensure you have brew installed:

    Copy Code
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

If you are using VS Code

You'll need the following extensions

To build and run:

  1. Clone the CodeProject.SenseAI repository from GitHub

  2. run /installers/Dev/setup_dev_env_win.bat (for windows) or bash setup_dev_env_linux.sh (for Ubuntu or macOS). This will download required assets and setup the Python environment.

  3. Open the main application folder in VSCode

  4. Click the "Run and Debug" button on the left hand tab bar (the arrow)

  5. From the dropdown at the top of the window, select Launch CodeProject.SenseAI 

  6. CLick the green arrow next to the dropdown

The dashboard webpage should launch after the code has built and the server has started.

If you are using Visual Studio

  1. Clone the CodeProject.SenseAI repository from GitHub

  2. Ensure you have the Python workflow enabled in Visual Studio. While not critical, it does help with debugging.

  3. run /installers/Dev/setup_dev_env_win.bat (for windows) or bash setup_dev_env_linux.sh (for Ubuntu). This will download required assets and setup the Python environment.

  4. Open the solution in Visual Studio and build the entire solution

  5. To run the Server and the demo application in DEBUG you can either

    1. Start both the projects in debug mode by

      1. In Solution Explorer, open demos / .NET and right-click on CodeProject.SenseAI.Playground and choose Debug -> Start new instance.
      2. In Solution Explorer, open src / API / Server and right-click on FrontEnd and choose Debug -> Start new instance.
    2. Configure Visual Studio to start multiple projects by

      1. In Solution Explorer, right-click on the solution and select Set Startup Projects... and configure Multiple startup projects as shown below. 
    3. Now when you start with or without debugging, both the Server and demo projects with start. Also, this will be shown on the toolbar as shown below.

  6. In Solution Explorer, open src / AnalysisLayer. Right click on DeepStack and choose Open Folder in File Explorer. Double click on the start.bat script. This script will ensure that the Python virtual environment is enabled and environment variables set.

At this point the Playground application should be indicting it has a connection to the API server, and the servwe should be dispatching requests to the backend Analysis layer.

License

CodeProject SenseAI is licensed under the Server-Side Public License

Release Notes and Roadmap

Previous

  • We started with a proof of concept on Windows 10+ only. Installs we via a simple BAT script, and the code has is full of exciting sharp edges. A simple dashboard and playground are included. Analysis is currently Python code only
  • Version checks are enabled to alert users to new versions
  • A new .NET implementation scene detection using the YOLO model to ensure the codebase is platform and tech stack agnostic
  • Blue Iris integration completed

Release 1.0 Beta - Current

  • Native Windows installer
  • Runs as Windows Service
  • Installs and Builds in Linux (Ubuntu) and macOS
  • General optimisation of the download payload sizes

Coming soon:

  • More AI modules in the backend analysis services
  • Support for GPU
  • Docker
  • Fully working on Linux and macOS

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK