yolov5, for a trained model, feed an image and get in return found classes with scores and bounding boxes as json - yolov5

I trained my custom yolo dataset, now my requirement is to feed an image to the model and get back a json with founded classes with scores and bounding boxes.
When I run detect.py, it looks that there is no option to configure this script to my needs, and I can only get back an image with bounding box and score placed on it.
How did you solve this problem?
Did you took parts of detect.py and modified to your needs, or is there probably a solution to it?
I have found the answer to it.
Once you have your model, you need this script to make it work and send the answer to a calling program.
I had just some problems with the paths, but in the end figured it out.
If you think it can be better, please let me know:
import os
import torch
# Important: Path here is taken not from the folder where the script is positioned, but from the root project folder
model = torch.hub.load(os.getcwd()+'/yolov5','custom', path='./yolov5/runs/train/lemon3/weights/best.pt', source='local', force_reload=True)
results = model("./dataset/test/images/fridge2.jpg")
# cord_thres contains 4 corners of bounding box, 5th array parameter is confidence score
labels, cord_thres = results.xyxyn[0][:, -1].numpy(), results.xyxyn[0][:, :-1].numpy()
print(labels, cord_thres)

Related

How to access text in UI element with JXA?

When you open a Terminal or iTerm window, you are shown a string like
Last login: Fri Jul 10 00:00:00 on ttys000
(base) my_username#my_hostname ~ %
I would like to be able to read this string into a variable in JXA.
This is how far I got until now.
1. Accessibility Inspector
With Accessibility Inspector I have discovered the hierarchy of UI elements which lead to the string I am looking for.
2. UI Browser
I have used UI Browser to navigate trough the hierarchy and obtain an Apple Script code to access the element; but I need JXA code.
3. Translating into code
In order to try to access the above UI hierarchy with JXA I have first enabled the Safari JavaScript debugger as explained here
and then I have written this code to invoke the debugger:
i_term = Application('iTerm')
i_term.quit()
i_term.activate()
delay(0.2)
debugger
Now, within the console of the debugger, I have tried to access the object by using the same variable naming shown in the first code snippet from this answer, that is
i_term.windows()[0].groups()[0].splitterGroups()[0].scrollAreas()[0]
At this point I have two problems:
I actually don't know if the object that I am trying accessing exists, because in the console I get uninformative output. I just know that i_term.windows()[0] is correct since if I type i_term.windows()[0].name() I get the string "zsh", which is the title of the window.
I don't know what's the name of the method/variable for the text UI element.
More generally, how I am describing in this other question (link coming in a edit I will soon make), I have tried printing in many ways the "content" of the variables I am working with, but I can't see the methods/values they contain. For instance: I would like to be able to see the list of methods/variables of i_term, in particular to know that it contains the method windows(), but I have found no way of getting this information. Being able to get this information would make possible to write the code much more easily, even with the current lack of documentation.
How can I obtain the string value of that text?
Why are you wanting to achieve your goal through UI scripting ? It's the most difficult kind of script to implement well, and the most likely to break.
I don't know whether you're aware, but the contents of a terminal window in both Terminal.app and iTerm.app can be retrieved through their AppleScript properties.
iTerm:
Application('com.googlecode.iterm2').windows[0].tabs[0].sessions[0].contents()
// OR: .currentWindow.currentSession.contents()
Terminal:
Application('com.apple.Terminal').windows[0].tabs[0].contents()
// OR: .windows[0].selectedTab.contents()
Side-bar:
To obtain an object reference—if one exists—to any given UI element on your screen, you need:
A definitive, unobstructed pixel belonging solely to the UI element in question, for which you can discern its (x, y) coordinates relative to the top-left of your screen. The "l" of "login" seems good:
Access privileges granted for Script Editor and System Events.
Then, when you run the command:
tell application id "com.apple.systemevents" to click at {x, y}
and, provided that the pixel you identified at coordinates (x, y) remains in view when the command executes, then the return value of the command will be the object reference to the UI element occupying the pixel at those coordinates.
If it returns missing value, the element isn't accessible.

Missing rooms issue with generatedMasterView and room material replacement using three.js

1st question: Missing room models
I used the model-derivative api from Forge with generatedMasterViews params to extract room nodes from the cloud Revit model (BIM360Team) it work perfectly fine for some model but I had the missing room issues with others.
Successful translated model
Some of the translated model's room nodes was missing and that's weird because their height and phase are the same and the rooms in 2d view were shown.
2D views has no problem at all
3D room nodes in the same floor were missing
So my question is, are their some limitation to extract the room geometry and convert to .svf files? e.g. publish view setting / view range / crop views / crop region ? or something I'm missing in my request ? I tried to align all the parameter or remove some component (e.g. furniture) but the result still the same. If you guys had noticed this issues before please help, your help would be appreciate.
2nd question: Room mesh and materials
I've write the function to highlight the selected elements and its work with almost every nodes except the room elements.
const highLightElement = (dbId, hexColor) => {
const myMaterial = createMaterial(hexColor)
const instanceTree = viewerApp.model.getInstanceTree()
const fragList = viewerApp.model.getFragmentList()
instanceTree.enumNodeFragments(dbId, function(fragId) {
fragList.setMaterial(fragId, myMaterial)
const fragProxy = viewerApp.impl.getFragmentProxy(viewerApp.model, fragId)
fragProxy.scale = new window.THREE.Vector3(scaleRatio, scaleRatio, scaleRatio)
fragProxy.updateAnimTransform()
}, true)
viewerApp.impl.invalidate(true)
}
The material of the room was gloomy white but if use section tool on it the section color already change to the color I choose (0xAB00EE - magenta). I don't know that is the room mesh different from others? or might be need some special procedure to do so?
Successful coloring nodes
Room nodes coloring
Z-section of colored room nodes
Regarding issue #1, it's possible that there are certain limitations preventing the Forge Model Derivative service from extracting room information but that would be more on the Revit side. If you wouldn't mind sharing the Revit model with us (confidentially) via forge (dot) help (at) autodesk (dot) com, we'd be happy to investigate it with the engineering team. In that case, please indicate which rooms are missing, too.
Regarding issue #2, from the Forge Viewer standpoint, rooms are just another geometry in the scene, with the only difference that this geometry is usually transparent and hidden by default. As far as I know, the visibility flag should not interfere with something like setting the material of a fragment but double-check if that really isn't the root cause.

Azure Logic Apps Http-Call Output (Outputs in general ?) Changed?

I logged in today to make another logic app today, and i noticed the return output for (in this example) a Http-call has changed.
Before, i have a memory of the whole object showing in the output of an action in the workflow. Now i just se this:
Picture below:
The output body is only a string in some kind of encryption...
Does the Workflow definition Language where i want to reach one specific value in the Json-body still work? Or was this Update a major overhall.
I'm lost here.
Does the Workflow definition Language where i want to reach one specific value in the Json-body still work?
Yes, We can still do it, seems like you at the designer over view of a run, if you want to see full of inputs and output click on the Run details tab on top of this screen.
enter image description here
The content is base64 encoded, if you want to decode with in the logic apps for any other action input, we can use the base64 function which are explained here (https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language#functions)

how to pass data from python to an HTML page

I am currently working on a program in python which keeps trak of a lot of builds.
This progress is reported in a html file which is current deleted and written again with the new data for me to update it. However I know this is not the idea approach though i have never really worked with html web pages in any degree what so ever.
But i would like to make it the right way but every time i search on something i just get how to pass data from a html page into a program. So what i am asking for is some guide lines as to what I need to look for to achive this.
Also any suggestion as to how the right approach whould be. I just need to pass data from my running python program to a html page.
Ad if im lucky maybe someone posseses a very simple exsample. like just a python constant passed to a text box or what ever on a html page.
Regards
Ephreal
#!/usr/bin/python3
__author__ = 'Aidan'
from urllib import request
goog_url = 'http://real-chart.finance.yahoo.com/table.csv?s=GOOG&d=8&e=2&f=2014&g=d&a=2&b=27&c=2014&ignore=.csv'
def dl(csv_url, dest):
response = request.urlopen(csv_url)
csv_str = str(response.read())
lines = csv_str.split("\\n")
fx = open(dest, "w")
for line in lines:
fx.write(line + "\n")
fx.close()
dl(goog_url, 'a.csv')
This will take a file from the web band save it to a filename of your choice.

Having trouble binding JSON data to a mobile list in Adobe Flash builder

Hi, i have been having some problems using JSON data in flash builder lately and I was hoping someone could help me out here.
I have spent the past month working solidly on this issue, so I HAVE been looking around, HAVE been trying out everything I can find or think of. I am simply stuck.
I have been working on a flex mobile application for the Blackberry Playbook tablet with Adobe Flash Builder 4.6. It is a reddit app, designed to give users the main reddit feed, subreddits, search function, hopefully log in stuff etc. Of course I need the aid of the reddit API to access this information, of which the documentation can be found here: https://github.com/reddit/reddit/wiki/API/ The api uses either XML or JSON formatted data.
Now onto my problem- Like mentioned above, i want to display the reddit feed inside the app. I want to be able to use a item renderer to customize the data that is shown within each entry of the list.
One entry would consist of:
1) a thumbnail of the image in the post
2) The title of the post
3) a 'like/dislike' button, but this is unimportant at the moment.
Of course to start out, i placed a spark List component onto the design view. Then i configured a new HTTP data service using the Data/Services panel. I specified http://www.reddit.com/r/all.json for the url. I configured the return type, and the did a Test Operation. Everything connected just fine. All the data came through as normal. I will give you an idea of what the data comes back as so that you may understand my issue later on.
Test Operation Results (json data structure):
NoName1
data
after
before
children
[0]
data
media_embed
score
id
title
thumbnail
url
(etc etc...)
kind
[1]
data
media_embed
score
title
thumbnail
(etc etc...)
kind
[2] (array continues)
modhash
kind
As you can see, to get to the thumnail for example, you would have to go through data.children[].data.thumnail. When I tried to bind this data to the spark List component, I specified the data service to be from the one above. Then I specified the Data provider option to be Children[], as this value is typically set to the array. Now this is where the trouble begins. The final option, Label Field, only gave me one value to choose from: 'kind'. So as you can tell, it wasnt expecting the data to go any further nested. It stops at the two value just within each array item, which would be Data and Kind, though it only offers me Kind. I need to go one level further to access Title and Thumbnail. This is my problem.
Now, I have analyzed the code for the binding, and I have tried altering it to accomodate the further nested value. No success what so ever. The following is the code that the binding generates:
<s:List
id="myList" width="100%" height="100%" change="myList_changeHandler(event)"
creationComplete="myList_creationCompleteHandler(event)" labelField="kind">
<s:AsyncListViewlist="{TypeUtility.convertToCollectionredditFeedJSONResult.lastResult.data.children)}"/>
<s:List>
Obviously i would want to have something like along the lines of:
"TypeUtility.convertToCollection(redditFeedJSONResult.lastResult.data.children.data" and then set the labelField="title" or "thumbnail".
I certainly hope someone can help me with this. I am out of my mind as to what to do. If you need any further clarification I would be happy to provide it. I tried to explain the situation above as clearly as possible. Thank you so much.
Ted
I have this situation often: get an XML or JSON data from the server, then trying to use it as a dataProvider for a spark.components.List or for a mx.controls.Menu and then they just wouldn't display the data as I want them, because something in the data is different from what they expect. And then they display wrong XML-children or [Object,Object,etc.]
And in such cases I just create an empty ArrayCollection() which serves as dataProvider instead (and can be sorted and/or filtered too). And when data comes from the server, I push() new Objects into it:
[Bindable]
private var _data:ArrayCollection = new ArrayCollection();
public function update(xlist:XMLList):void {
_data.length = 0;
for each (var xml:XML in xlist)
_data.push({label: xml, event: xml.#event});
}
This always works. And if you get your next problem - flickering of the List, then that is solvable by merging data too.
Good luck with your Playbook development, which is a cool piece of hardware :-)