Giter Club home page Giter Club logo

imaginem-functions's Introduction

Imaginem-Functions

Azure functions for the configurable image recognition and classification pipeline

Details on how to develop for Azure function and the Azure Function tools for Visual Studio

Adding a function

Each function is added to its own folder and contains the following artifacts:

function.json   // your function binding
project.json    // your project dependencies
run.csx         // your code
test.json       // your test message

Implementing the function.json

Here an example implementation for samplefunction:

#load "..\Common\FunctionHelper.csx"

using System;
using System.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;

// your classifier's name
private const string ClassifierName = "samplefunction";

public static void Run(string inputMsg, TraceWriter log)
{
    log.Verbose($"Process {inputMsg}");
    PipelineHelper.Process(SampleFunction, ClassifierName, inputMsg, log);
}
public static dynamic SampleFunction(dynamic inputJson, string imageUrl, TraceWriter log)
{ 
    // TODO: do your processing here and return the results

    return new {
        stringOutput = "your output string value",
        intOutput = 10 
    };
}

Declare the dependencies

As the last step, you need to declare the functions dependencies in dependencies.json. In the example below, facematch depends on faceprint and faceprint depends on facedetection.

{
  "facecrop": ["facedetection"],
  "facedetection": [],
  "facematch": ["faceprint"],
  "faceprint": ["facedetection"],
  "generalclassification": [],
  "ocr": []
}

Therefore the pipeline definition for facematch would look like "facedetection,faceprint,facematch"

Create the test message

Each function should contain a simple test message stored in test.json:

{
  "job_definition": {
    "batch_id": "mybatchid",
    "id": "myjobid",
    "input": {
      "image_url": "your image url",
      "image_classifiers": [ "classifier1", "classifier2" ]
    },
    "processing_pipeline": [ "your_input_queue_name", "your_output_queue_name" ],
    "processing_step": 0

  },
  "job_output" : {
    "sample_job1" : {
      "output": "sample_job1 output"
    }
  }
}

Ensure you add all needed input data (your dependencies) as part of the job_output and set your_input_queue_name and your_input_queue_name for the processing_pipeline property.

Test the function locally

To test your functions locally, you need to update your appsettings.json file:

  {
    "IsEncrypted": false,
    "Values": {
      "FACES_CONTAINER": "faces",
      "SQL_CONNECTION_STRING": "<YOUR_SQL_CONNECTION_STRING>",
      "FACE_API_KEY": "<YOUR_FACE_API_KEY>",
      "VISION_API_KEY": "<YOUR_VISION_API_KEY",
      "AzureWebJobsStorage": "<YOUR_STORAGE_CONNECTION_STRING>",
      "AzureWebJobsDashboard": "<YOUR_STORAGE_CONNECTION_STRING>"
    }
  }

Once you've done that, you can either run your functions in Visual Studio or use azure-functions-cli directly:

npm i -g azure-functions-cli

To run your function, just execute

func run YourFunctionName

to run the tests, run the Imaginem-Cli. The following triggers the SampleFunction by adding its test.json to the sample queue.

.\Imaginem-Cli.exe test SampleFunction sample

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.