twentybn 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +80 -2
- data/lib/twentybn/image.rb +2 -2
- data/lib/twentybn/version.rb +1 -1
- data/test/twentybn/image_test.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 15037c788b461bc1d7343c9d4fd9f519287e5273
|
|
4
|
+
data.tar.gz: 5b573ad757d66745cddabc9890666a971c29663f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 68eb494036f06df1f962b0b0dbb4b228ed1dd7950a4b3b95cfb4f77e31eca2c7466ba8f4bb5a7a3d103e414ced914dcc92c7a3513f34f5f65ba5c59231c712f3
|
|
7
|
+
data.tar.gz: 127bae132cd9bb6b20488383f88199009f6ce65c7d84040cd155c2fae5f341b2eb39c4c516368da0e6e07a4ba243e8340d03b69ddd424847301f24bc2d4bd6b0
|
data/README.md
CHANGED
|
@@ -24,14 +24,41 @@ In order to get an API key, you need to sign up for free at https://cortex.twent
|
|
|
24
24
|
|
|
25
25
|
## Basic usage
|
|
26
26
|
|
|
27
|
+
### Image tagging
|
|
28
|
+
|
|
29
|
+
Image tagging returns tags for a given image by applying a neural networks based classifier on the image. The basic usage is as follows:
|
|
30
|
+
|
|
27
31
|
```ruby
|
|
28
32
|
require 'twentybn'
|
|
29
33
|
TwentyBN.api_key = 'PUT_API_KEY_HERE'
|
|
30
34
|
tags = TwentyBN.image("/path/to/an/image.jpg").tag
|
|
31
|
-
answer = TwentyBN.image("/path/to/an/image.jpg").ask("What is the man doing?")
|
|
32
35
|
```
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
The result will look like this:
|
|
38
|
+
```ruby
|
|
39
|
+
{
|
|
40
|
+
"result"=> {
|
|
41
|
+
"scores"=> [
|
|
42
|
+
0.6320463418960571,
|
|
43
|
+
0.3534449338912964,
|
|
44
|
+
0.00861052330583334,
|
|
45
|
+
0.001009061117656529,
|
|
46
|
+
0.0009043768513947725
|
|
47
|
+
],
|
|
48
|
+
"tags"=> [
|
|
49
|
+
"tabby, tabby cat",
|
|
50
|
+
"tiger cat",
|
|
51
|
+
"Egyptian cat",
|
|
52
|
+
"lens cap, lens cover",
|
|
53
|
+
"cup"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The default image classifier knows one thousand objects and returns the top 5 most likely results.
|
|
60
|
+
|
|
61
|
+
### Configure Rails application
|
|
35
62
|
|
|
36
63
|
If you use Rails, you can add omit the first two lines and add the API key to your environment config file as follows:
|
|
37
64
|
|
|
@@ -39,6 +66,57 @@ If you use Rails, you can add omit the first two lines and add the API key to yo
|
|
|
39
66
|
config.twentybn_api_key = 'PUT_API_KEY_HERE'
|
|
40
67
|
```
|
|
41
68
|
|
|
69
|
+
### Using alternative image classifiers
|
|
70
|
+
|
|
71
|
+
There are also two alternative image classifiers available, `:categories` and `:places`. You can use them as follows:
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
tags = TwentyBN.image("/path/to/an/image.jpg").tag(:categories)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
tags = TwentyBN.image("/path/to/an/image.jpg").tag(:places)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Roll your own classifier
|
|
82
|
+
|
|
83
|
+
You can train your own image classifier at https://cortex.twentyn.com under `Applications` -> `Image Tagging` -> `Custom Image Taggers`. Here, you can create a classifier, add class labels to it and upload some example images for each class. Finally, you can click `train` to build your own classifier automatically. As a result, you get a `ModelID` which you can use to access your custom image classifier as follows:
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
tags = TwentyBN.image("/path/to/an/image.jpg").tag("PUT_YOUR_MODEL_ID_HERE")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Visual Question Answering (VQA)
|
|
90
|
+
|
|
91
|
+
Visual Question Answering means that you can ask a natural language question about a given image. You can use it as follows:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
answer = TwentyBN.image("/path/to/an/image.jpg").ask("What is the man doing?")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The result will look like this:
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
{
|
|
101
|
+
"result"=> {
|
|
102
|
+
"answers"=> [
|
|
103
|
+
"PLAYING FRISBEE",
|
|
104
|
+
"CATCHING FRISBEE",
|
|
105
|
+
"FLYING KITE",
|
|
106
|
+
"FLYING KITES"
|
|
107
|
+
"SKATEBOARDING",
|
|
108
|
+
],
|
|
109
|
+
"scores"=> [
|
|
110
|
+
9.731609344482422,
|
|
111
|
+
8.681315422058105,
|
|
112
|
+
7.385936737060547,
|
|
113
|
+
7.113564491271973,
|
|
114
|
+
6.711164474487305
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
42
120
|
## License
|
|
43
121
|
|
|
44
122
|
Copyright (c) 2016 Twenty Billion Neurons GmbH, Berlin, Germany
|
data/lib/twentybn/image.rb
CHANGED
|
@@ -29,7 +29,7 @@ module TwentyBN
|
|
|
29
29
|
request.url '/v1/vqa'
|
|
30
30
|
request.body = JSON.generate(data)
|
|
31
31
|
end
|
|
32
|
-
return response.body
|
|
32
|
+
return JSON.parse(response.body)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def tag(model=:objects)
|
|
@@ -49,7 +49,7 @@ module TwentyBN
|
|
|
49
49
|
end
|
|
50
50
|
request.body = JSON.generate(data)
|
|
51
51
|
end
|
|
52
|
-
return response.body
|
|
52
|
+
return JSON.parse(response.body)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def image_base64
|
data/lib/twentybn/version.rb
CHANGED
data/test/twentybn/image_test.rb
CHANGED
|
@@ -8,7 +8,7 @@ class ImageTest < Minitest::Test
|
|
|
8
8
|
VCR.use_cassette('tag_objects') do
|
|
9
9
|
|
|
10
10
|
response = TwentyBN.image("./test/fixtures/files/test_image.jpg").tag
|
|
11
|
-
result =
|
|
11
|
+
result = response['result']
|
|
12
12
|
|
|
13
13
|
tag_result_fixture = YAML.load_file('./test/fixtures/results.yml')['tag_objects_result']
|
|
14
14
|
|
|
@@ -21,7 +21,7 @@ class ImageTest < Minitest::Test
|
|
|
21
21
|
VCR.use_cassette('tag_places') do
|
|
22
22
|
|
|
23
23
|
response = TwentyBN.image("./test/fixtures/files/test_image.jpg").tag(:places)
|
|
24
|
-
result =
|
|
24
|
+
result = response['result']
|
|
25
25
|
|
|
26
26
|
tag_result_fixture = YAML.load_file('./test/fixtures/results.yml')['tag_places_result']
|
|
27
27
|
|
|
@@ -34,7 +34,7 @@ class ImageTest < Minitest::Test
|
|
|
34
34
|
VCR.use_cassette('tag_categories') do
|
|
35
35
|
|
|
36
36
|
response = TwentyBN.image("./test/fixtures/files/test_image.jpg").tag(:categories)
|
|
37
|
-
result =
|
|
37
|
+
result = response['result']
|
|
38
38
|
|
|
39
39
|
tag_result_fixture = YAML.load_file('./test/fixtures/results.yml')['tag_categories_result']
|
|
40
40
|
|
|
@@ -47,7 +47,7 @@ class ImageTest < Minitest::Test
|
|
|
47
47
|
VCR.use_cassette('tag_custom') do
|
|
48
48
|
|
|
49
49
|
response = TwentyBN.image("./test/fixtures/files/test_image.jpg").tag("9b80ddb9-2d02-436f-86ba-f9a3e679de7a")
|
|
50
|
-
result =
|
|
50
|
+
result = response['result']
|
|
51
51
|
|
|
52
52
|
tag_result_fixture = YAML.load_file('./test/fixtures/results.yml')['tag_custom_result']
|
|
53
53
|
|
|
@@ -61,7 +61,7 @@ class ImageTest < Minitest::Test
|
|
|
61
61
|
|
|
62
62
|
question = "What is the dog doing?"
|
|
63
63
|
response = TwentyBN.image("./test/fixtures/files/test_image.jpg").ask(question)
|
|
64
|
-
result =
|
|
64
|
+
result = response['result']
|
|
65
65
|
|
|
66
66
|
ask_result_fixture = YAML.load_file('./test/fixtures/results.yml')['ask_result']
|
|
67
67
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: twentybn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ingo Bax
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-11-
|
|
11
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|