Skip to content

Commit

Permalink
Merge pull request #4 from roboflow/add-tests
Browse files Browse the repository at this point in the history
Added the fruits SOM image and logic fixes
  • Loading branch information
stellasphere authored Nov 17, 2023
2 parents 8b3fc94 + 4800feb commit 3296131
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
Binary file added images/fruits_som.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h2>Response Time</h2>
</div>
<div class="chart">
<div class="chart_box chart_box_green">
<p>4.12 ms</p>
<p>4.12 s</p>
</div>
</div>
</div>
Expand All @@ -80,8 +80,7 @@ <h2>Zero-Shot Classification</h2>
<h3><span class="explainer_icon far fa-comment-dots"></span>Prompt</h3>
<pre>
What is in the image? Return the class of the object in the image. Here are the classes: Toyota Camry, Tesla Model 3. You can only return one class from that list.
</pre
>
</pre>
<h3><span class="explainer_icon far fa-image"></span>Image</h3>
<img class="test_image" src="images/car.jpeg" />
<h3><span class="explainer_icon far fa-sparkles"></span>Result</h3>
Expand Down
2 changes: 1 addition & 1 deletion results/2023-11-17.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"zero_shot_classification": {"score": 1, "response_time": 1.5038928985595703, "result": "Toyota Camry"}, "count_fruit": {"score": 0, "response_time": 2.0013718605041504, "result": "9"}, "document_ocr": {"score": 1, "response_time": 10.280664682388306, "result": "I was thinking earlier today that I have gone through, to use the lingo, eras of listening to each of Swift's Eras. Meta indeed. I started listening to Ms. Swift's music after hearing the Midnights album. A few weeks after hearing the album for the first time, I found myself playing various songs on repeat. I listened to the album in order multiple times."}, "handwriting_ocr": {"score": 1, "response_time": 8.720427989959717, "result": "The words of songs on the album have been echoing in my head all week. \"Fades into the grey of my day old tea.\""}, "extraction_ocr": {"score": 1.0, "response_time": 4.255826950073242, "result": "[{'name': 'MARY THOMAS', 'time_per_day': 1, 'medication': 'ATENOLOL', 'dosage': 100, 'rx_number': '1234567-12345'}]"}, "math_ocr": {"score": 1.0, "response_time": 2.5475921630859375, "result": "3x^2-6x+2"}, "object_detection": {"score": 0.18220793140407288, "response_time": 5.249211311340332, "result": "{'x': 0.4, 'y': 0.2, 'width': 0.2, 'height': 0.4}"}}
{"zero_shot_classification": {"score": 1, "response_time": 1.8139240741729736, "result": "Toyota Camry"}, "count_fruit": {"score": 0, "response_time": 2.2961227893829346, "result": "9"}, "document_ocr": {"score": 1, "response_time": 3.707613945007324, "result": "I was thinking earlier today that I have gone through, to use the lingo, eras of listening to each of Swift's Eras. Meta indeed. I started listening to Ms. Swift's music after hearing the Midnights album. A few weeks after hearing the album for the first time, I found myself playing various songs on repeat. I listened to the album in order multiple times."}, "handwriting_ocr": {"score": 1, "response_time": 7.602664232254028, "result": "The words of songs on the album have been echoing in my head all week. \"Fades into the grey of my day old tea.\""}, "extraction_ocr": {"score": 1.0, "response_time": 3.052698850631714, "result": "[{'name': 'MARY THOMAS', 'time_per_day': 1, 'medication': 'ATENOLOL', 'dosage': 100, 'rx_number': '1234567-12345'}]"}, "math_ocr": {"score": 0.9, "response_time": 2.2950241565704346, "result": "3x^{2}-6x+2"}, "object_detection": {"score": 0, "response_time": 2.439383029937744, "result": "Failed to produce a valid JSON output"}, "set_of_mark": {"score": 0.4782608695652174, "response_time": 4.843470096588135, "result": "```json\n[\n 10, \n 11, \n 12, \n 13, \n 14, \n 15, \n 16, \n 17, \n 18, \n 19, \n 20, \n 21, \n 22, \n 23, \n 24, \n 25, \n 26, \n 27\n]\n```"}}
2 changes: 1 addition & 1 deletion template.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h2>Response Time</h2>
</div>
<div class="chart">
<div class="chart_box chart_box_green">
<p>{{results['avg_time']}} ms</p>
<p>{{results['avg_time']}} s</p>
</div>
</div>
</div>
Expand Down
43 changes: 23 additions & 20 deletions web.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def extraction_ocr():

code_regex = r'```[a-zA-Z]*\n(.*?)\n```'
code_blocks = re.findall(code_regex,result, re.DOTALL)

if(len(code_blocks) == 0): return 0, inference_time, "Failed to produce a valid JSON output"
answer_array = json.loads(code_blocks[0])

correct_array = [
Expand Down Expand Up @@ -190,6 +190,7 @@ def math_ocr():

code_regex = r'```[a-zA-Z]*\n(.*?)\n```'
code_blocks = re.findall(code_regex,result, re.DOTALL)
if(len(code_blocks) == 0): return 0, inference_time, "Failed to produce a valid JSON output"
answer_array = json.loads(code_blocks[0])
answer_equation = answer_array[0].replace(" ", "")

Expand All @@ -213,6 +214,7 @@ def object_detection():

code_regex = r'```[a-zA-Z]*\n(.*?)\n```'
code_blocks = re.findall(code_regex, result, re.DOTALL)
if(len(code_blocks) == 0): return 0, inference_time, "Failed to produce a valid JSON output"
answer = json.loads(code_blocks[0])

correct = {'x': 0.465, 'y': 0.42, 'width': 0.37, 'height': 0.38}
Expand All @@ -232,31 +234,32 @@ def object_detection():
return iou, inference_time, str(answer)

def set_of_mark():
base_model = GPT4V(
ontology=CaptionOntology({"none": "none"}),
api_key=os.environ["OPENAI_API_KEY"],
)
base_model = GPT4V(
ontology=CaptionOntology({"none": "none"}),
api_key=os.environ["OPENAI_API_KEY"],
)

result, inference_time = base_model.predict(
"images/fruits_som.png",
classes=[],
result_serialization="text",
prompt="Find all the fruits in this image and return a JSON array of all the applicable numbers.",
)
result, inference_time = base_model.predict(
"images/fruits_som.png",
classes=[],
result_serialization="text",
prompt="Find all the fruits in this image and return a JSON array of all the applicable numbers.",
)

code_regex = r'```[a-zA-Z]*\n(.*?)\n```'
code_blocks = re.findall(code_regex,result, re.DOTALL)
answer = json.loads(code_blocks[0])
code_regex = r'```[a-zA-Z]*\n(.*?)\n```'
code_blocks = re.findall(code_regex, result, re.DOTALL)
if(len(code_blocks) == 0): return 0, inference_time, "Failed to produce a valid JSON output"
answer = json.loads(code_blocks[0])

correct = [35,40,26,2,13,17,29,21,10,42,8,43,0,11,7,4,12,27,37,39,22,15,25]
correct = [35,40,26,2,13,17,29,21,10,42,8,43,0,11,7,4,12,27,37,39,22,15,25]

score = 0
for guess in answer:
if guess in correct: score += 1
score = 0
for guess in answer:
if guess in correct: score += 1

accuracy = score/len(correct)
accuracy = score/len(correct)

return accuracy, inference_time, result
return accuracy, inference_time, result


tests = [
Expand Down

0 comments on commit 3296131

Please sign in to comment.