Giter Club home page Giter Club logo

matroid-ruby's Introduction

Features

Installation

Add this line to your application's Gemfile:

gem 'matroid'

And then execute:

$ bundle

Or install it yourself as:

$ gem install matroid

Usage

This API wrapper allows you to easily create and use Matroid detectors for classifying various media. It is designed to allow you to use detectors without any notion of the API.

Check the documentation for the complete reference of available methods.

Authenticate your session

The Matroid API relies on the use of access tokens. The easiest way to automatically authenticate your usage and handle access tokens is to declare MATROID_CLIENT_ID and MATROID_CLIENT_SECRET in your environment. For example, place the following in your .env file (this library includes the dotenv gem):

MATROID_CLIENT_ID=XXXXXXXXXXXXXXXXXXX
MATROID_CLIENT_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXX

Also, you may call Matroid.authenticate(MATROID_CLIENT_ID, MATROID_CLIENT_SECRET) before any other methods and the token will be stored in the instance and refreshed as needed.

Example API usage

Authentication

require 'matroid'

MATROID_CLIENT_ID=XXXXXXXXXXXXXXXXXXX
MATROID_CLIENT_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXX

Matroid.authenticate(MATROID_CLIENT_ID, MATROID_CLIENT_SECRET)

# Check user account info like Matroid Credits balance
Matroid.account_info

Query for Detectors

# Get detector by id
detector = Matroid::Detector.find_by_id('5893f98530c1c00d0063835b')

# Get detectors by query
# Search by one or more of :labels, :name, :state, :id, :permission_level, :owner, :detector_type
# :labels and :name queries can be String or Regexp
detector = Matroid::Detector.find(id: '5893f98530c1c00d0063835b').first
cat_detectors = Matroid::Detector.find(name: 'cat')
cat_detector_id = Matroid::Detector.find(labels: 'cat', owner: true, state: 'trained').first.id

# Find published detectors
cat_detectors = Matroid::Detector.find(name: 'cat', published: true)
cat_detector_id = Matroid::Detector.find(labels: 'cat', state: 'trained', published: true).first.id

# convenience methods
#  .find_by_id(String)
#  .find_one(Hash)
#  .find_by_<attribute>(String)
#  .find_one_by_<attribute>(String)

# View cached detectors from previous searches
all_detectors = Matroid::Detector.cached

Use Detector class methods

# Get detector details
detector.to_hash #=> Hash of all the details (or you can get them separately as below)
detector.info #=> displays detector attributes in a nice printout

detector.id #=> "5893f98530c1c00d0063835b"
detector.name #=> "My cool detector"
detector.state #=> "trained"
detector.labels #=> ["label 1", "label 2", ...]
detector.permission_level #=> "private"
detector.owner #=> true
detector.training #=> "successful"
detector.type #=> "object", "face", "facial_characteristics"

# Create a detector
detector = Matroid::Detector.create('PATH/TO/ZIP/FILE', 'My awesome detector', 'general') # uploads labels and images
detector.id #=> "XxXxXxXxXxXxXxXxXxXxXxXxXxXxXx"
detector.name #=> "My awesome detector"
detector.state #=> "pending"
detector.labels #=> ["label 1", "label 2", ...]
detector.permission_level #=> "private"
detector.owner #=> true
detector.type #=> "general"
detector.train # submits the detector for training
# You can repeatedly call detector.info to get the updates on the training

# Use a detector
detector = Matroid::Detector.find_by_id('5893f98530c1c00d0063835b')

# Classifying an image returns a hash of the detected labels (with probabilities)
# along with bounding box information (if applicable)
image_file_path = 'PATH/TO/IMAGE/FILE'
image_url = 'https://www.example.com/images/some_image.jpg'
detector.classify_image_url(image_url)
detector.classify_image_file(image_file_path)

# Classifying a video returns a hash { "video_id" => "dfoguhd078yd7dg87dfvsdf7" }
# which can later be used to check on the classification.
# A video takes some time to classify depending on the length and size of the video uploaded.
youtube_url = 'https://www.youtube.com/watch?v=0qVOUD76JOg'
video_file_path = 'PATH/TO/VIDEO/FILE'
detector.classify_video_url(youtube_url)
detector.classify_video_file(video_file_path)

# Call the following repeatedly to check the progress on the video classification results
detector_id = 'dfoguhd078yd7dg87dfvsdf7'
Matroid.get_video_results(detector_id) #=> details of timestamps with labels, etc.

More functionality coming soon.

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

matroid-ruby's People

Contributors

julian-matroid avatar ryan-matroid avatar

Watchers

James Cloos avatar Reza Zadeh avatar  avatar  avatar  avatar

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.