#π Looking for ideas
43 messages Β· Page 1 of 1 (latest)
@winged arch
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
use enum instead of a long dictionary with numbers to names
can make confidence a variable which decreases if no matches found but you know there should be one, may not be appropriate in your case
anything else like any other ideas associted with like how to mayble make more classes or stuff able to be recognized
explain further
k i figure it out i hate using enum
Labels(IntEnum):
Person = 1
Bicycle = auto()
Car = auto()
...
would i put in within the def statement
no
can make BBox a dataclass
so you don't have to use all these bare variables like ymin, xmin, ymax, xmax = bbox
can do a class for the whole thing
what is a data class
nicer way to associate variables with a thing
instead of manually like what you're doing there
see how you have to store 2 things in the var name like that
ymax
anyway it's more an evolution to cleaner programming, not going to effect your functionality
ok is that associated with OOP ive heard alot about that
not really, I mean technically it is but not so much
it basically just allows you to use less "basic" variables and dicts and stuff
Well, more about making a "record" like object with names. You can use Python classes for OOP (which is what we largely do) but they are also in a sense records with named fields. Eg:
class BBox:
def __init__(self, ymin, xmin, ymax, xmax):
self.ymin = ymin
self.xmin = xmin
self.ymax = ymax
self.xmax = xmax
then you could go bbox = BBox(*detections['detection_boxes'][i]) and then use bbox.ymin etc to refer to the stored values i.e. using nice names.
allows you to do stuff like
Dataclasses let you define these more succinctly:
from dataclasses import dataclass
@dataclass
class BBox:
ymin: int
xmin: int
ymax: int
xmax: int
and another way stacking them to have even more granular
@dataclass
class XY:
x: int
y: int
@dataclass
class BBox:
min: XY
max: XY
# ...
# now you can talk to your data like this:
box.min.y
box.max.y
# etc
print(box.min.x) # and so on
Now show the assignment statement to unpack his detections['detection_boxes'][i] into this nested structure π
Anyway, yes, that works though personally I'd invert the nesting for box.y.min.
The OP should use whatever they find more expressive and clear.
but would these changes yall are saying i should make allow me to import these functions into the other program with the main ai that im planning on this program being the eyes for
You can import the functions (and the class names) as you see fit. They're just names in this modules namespace. And import statement just pulls names from another namespace in for use here.
(Well, really, pulling in their values, but the effect is what you expect.)
gotcha so basicly just do it as i usually would for anything else
that im importing in that i make
and it should work correctly
?
Yes.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.