deepstack 1.2.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deep_stack/custom_model.rb +26 -0
- data/lib/deep_stack/deep_stack.rb +20 -13
- data/lib/deep_stack/face.rb +19 -0
- data/lib/deep_stack/scene.rb +3 -2
- data/lib/deep_stack/version.rb +1 -1
- metadata +3 -3
- data/lib/deep_stack/custom.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d3a74d72c68a1aef4f04d6b3a04d67cb26c89daf0bdfa1ba85a1cbfd904bd76
|
4
|
+
data.tar.gz: 2cc1bfddab42ebbc72ef9e1a90c35cc577e5a46e0db8d3900c42bc24dd15af64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b12be0063b456923b065db6d9ae277aa30a32bc2a4e1c895a646b039d4770bd36dd296effc788cb7ace506be23dd64a836d11e77210184eb278b0b82ddda1818
|
7
|
+
data.tar.gz: ed627f25f85c15551b0758e9d87ea002f0cb95efdec5a6c31a92dd9a11936fc7bdddf51a570e61ebffc5995ce869c17d703df277421578428c187f7a724d64d5
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DeepStack
|
4
|
+
# Support for using Custom Models with DeepStack
|
5
|
+
module CustomModel
|
6
|
+
#
|
7
|
+
# Return predictions using a custom model.
|
8
|
+
# Custom models are *.pt models that have been saved in DeepStack's modelstore directory.
|
9
|
+
# See https://docs.deepstack.cc/custom-models/deployment/index.html
|
10
|
+
#
|
11
|
+
# @param [String] model custom model name
|
12
|
+
# @param [Object] image binary data or a File object
|
13
|
+
# @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
|
14
|
+
#
|
15
|
+
# @return [Array] if successful, an array of DeepStack predictions
|
16
|
+
#
|
17
|
+
# @return [nil] if error
|
18
|
+
#
|
19
|
+
def custom_model(model, image, **options)
|
20
|
+
target = "vision/custom/#{model}"
|
21
|
+
api_post(target, image, **options)&.dig('predictions')
|
22
|
+
end
|
23
|
+
# @deprecated Use {custom_model} instead
|
24
|
+
alias custom_inference custom_model
|
25
|
+
end
|
26
|
+
end
|
@@ -5,7 +5,7 @@ require 'json'
|
|
5
5
|
require_relative 'face'
|
6
6
|
require_relative 'detection'
|
7
7
|
require_relative 'scene'
|
8
|
-
require_relative '
|
8
|
+
require_relative 'custom_model'
|
9
9
|
require_relative 'version'
|
10
10
|
|
11
11
|
# DeepStack API
|
@@ -13,22 +13,34 @@ class DeepStack
|
|
13
13
|
include DeepStack::Face
|
14
14
|
include DeepStack::Detection
|
15
15
|
include DeepStack::Scene
|
16
|
-
include DeepStack::
|
16
|
+
include DeepStack::CustomModel
|
17
17
|
|
18
18
|
#
|
19
19
|
# Create a deepstack object connected to the given URL
|
20
20
|
#
|
21
21
|
# @param [String] base_url the url to DeepStack's server:port
|
22
22
|
# @param [String] api_key an optional API-KEY to use when connecting to DeepStack
|
23
|
-
# @param [String]
|
23
|
+
# @param [String] api_key an optional API-KEY to use when connecting to DeepStack
|
24
|
+
# @param [Integer] verify_mode sets the flags for server the certification verification at
|
25
|
+
# beginning of SSL/TLS session.
|
26
|
+
# +OpenSSL::SSL::VERIFY_NONE+ or +OpenSSL::SSL::VERIFY_PEER+ are acceptable.
|
24
27
|
#
|
25
28
|
# @example
|
26
29
|
# DeepStack.new('http://127.0.0.1:5000')
|
27
30
|
#
|
28
|
-
|
31
|
+
# # Using API KEY:
|
32
|
+
# DeepStack.new('http://127.0.0.1:5000', api_key: 'secret', admin_key: 'supersecret')
|
33
|
+
#
|
34
|
+
# # Connect to SSL with a self-signed certificate
|
35
|
+
# DeepStack.new('https://localhost:443', verify_mode: OpenSSL::SSL::VERIFY_NONE)
|
36
|
+
#
|
37
|
+
def initialize(base_url, api_key: nil, admin_key: nil, verify_mode: nil)
|
29
38
|
@base_url = base_url
|
30
39
|
@auth = { api_key: api_key, admin_key: admin_key }.select { |_k, v| v } # remove nil values
|
31
|
-
|
40
|
+
uri = URI(base_url)
|
41
|
+
http_options = {}
|
42
|
+
http_options[:verify_mode] = verify_mode if verify_mode
|
43
|
+
@http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.instance_of?(URI::HTTPS), **http_options)
|
32
44
|
end
|
33
45
|
|
34
46
|
#
|
@@ -60,10 +72,7 @@ class DeepStack
|
|
60
72
|
# Close the HTTP connection to DeepStack server
|
61
73
|
#
|
62
74
|
def close
|
63
|
-
@
|
64
|
-
@http&.finish
|
65
|
-
@http = nil
|
66
|
-
end
|
75
|
+
@http.finish if @http&.started?
|
67
76
|
end
|
68
77
|
|
69
78
|
private
|
@@ -80,10 +89,8 @@ class DeepStack
|
|
80
89
|
form_data = combine_images_and_args(images.flatten, **args)
|
81
90
|
req = Net::HTTP::Post.new(uri)
|
82
91
|
req.set_form(form_data, 'multipart/form-data')
|
83
|
-
@
|
84
|
-
|
85
|
-
@http.request(req)
|
86
|
-
end
|
92
|
+
@http.start unless @http.started?
|
93
|
+
@http.request(req)
|
87
94
|
end
|
88
95
|
|
89
96
|
def combine_images_and_args(*images, **args)
|
data/lib/deep_stack/face.rb
CHANGED
@@ -77,5 +77,24 @@ class DeepStack
|
|
77
77
|
target = 'vision/face/register'
|
78
78
|
api_post(target, images, userid: userid)&.dig('success') == true
|
79
79
|
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# Call DeepStack's Face Match service. Compare two different pictures and tells the similarity between them.
|
83
|
+
#
|
84
|
+
# @example
|
85
|
+
# image1 = File.read('obama1.jpg')
|
86
|
+
# image2 = File.read('obama2.jpg')
|
87
|
+
# puts deepstack.face_match(image1, image2) > 0.6 ? 'similar' : 'different'
|
88
|
+
#
|
89
|
+
# @param [Array] *images two images to compare
|
90
|
+
# @param [kwargs] **args optional arguments to the API call
|
91
|
+
#
|
92
|
+
# @return [Float] The similarity score (0-1)
|
93
|
+
# @return [nil] if failed
|
94
|
+
#
|
95
|
+
def face_match(*images, **args)
|
96
|
+
target = 'vision/face/match'
|
97
|
+
api_post(target, images, **args)&.dig('similarity')
|
98
|
+
end
|
80
99
|
end
|
81
100
|
end
|
data/lib/deep_stack/scene.rb
CHANGED
@@ -4,14 +4,15 @@ class DeepStack
|
|
4
4
|
# Scene Recognition
|
5
5
|
module Scene
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# Call the scene recognition API to classify an image into one of the supported scenes.
|
8
8
|
#
|
9
9
|
# @param [Object] image binary data or a File object
|
10
10
|
# @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
|
11
11
|
#
|
12
|
-
# @return [Hash] if successful, DeepStack result hash {'label' => 'scene', 'confidence' => 2.2}
|
12
|
+
# @return [Hash] if successful, DeepStack result hash +{'label' => 'scene', 'confidence' => 2.2}+
|
13
13
|
#
|
14
14
|
# @return [nil] if error
|
15
|
+
#
|
15
16
|
def identify_scene(image, **options)
|
16
17
|
target = 'vision/scene'
|
17
18
|
api_post(target, image, **options)
|
data/lib/deep_stack/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deepstack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmy Tanagra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -17,7 +17,7 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- lib/deep_stack/
|
20
|
+
- lib/deep_stack/custom_model.rb
|
21
21
|
- lib/deep_stack/deep_stack.rb
|
22
22
|
- lib/deep_stack/detection.rb
|
23
23
|
- lib/deep_stack/face.rb
|
data/lib/deep_stack/custom.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class DeepStack
|
4
|
-
# Custom Model
|
5
|
-
module Custom
|
6
|
-
#
|
7
|
-
# Register a custom inference method for convenience.
|
8
|
-
# The custom method is called "identify_<modelname>"
|
9
|
-
# Example:
|
10
|
-
# deepstack.register_custom_model('license_plate')
|
11
|
-
# deepstack.identify_license_plate(image)
|
12
|
-
#
|
13
|
-
# @param [Array] models a list of one or more custom model names to register
|
14
|
-
#
|
15
|
-
# @return [<Type>] <description>
|
16
|
-
#
|
17
|
-
def self.register_model(*models)
|
18
|
-
models.flatten.each do |model|
|
19
|
-
method_name = 'identify_'.concat model.gsub(/-+/, '_') # convert - to _
|
20
|
-
define_method(method_name) do |image, **options|
|
21
|
-
custom_inference(model, image, options)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# Return predictions using a custom model
|
28
|
-
#
|
29
|
-
# @param [String] model custom model name
|
30
|
-
# @param [Object] image binary data or a File object
|
31
|
-
# @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
|
32
|
-
#
|
33
|
-
# @return [Array] if successful, an array of DeepStack predictions
|
34
|
-
#
|
35
|
-
# @return [nil] if error
|
36
|
-
#
|
37
|
-
def custom_inference(model, image, **options)
|
38
|
-
target = "vision/custom/#{model}"
|
39
|
-
api_post(target, image, options)&.dig('predictions')
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|