#πŸ”’ Looking for ideas

43 messages Β· Page 1 of 1 (latest)

winged arch
opaque sinewBOT
#

@winged arch

Python help channel opened

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.

wet nexus
#

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

winged arch
#

anything else like any other ideas associted with like how to mayble make more classes or stuff able to be recognized

winged arch
wet nexus
winged arch
#

k i figure it out i hate using enum

wet nexus
#
Labels(IntEnum):
    Person = 1
    Bicycle = auto()
    Car = auto()
    ...
winged arch
#

would i put in within the def statement

wet nexus
#

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

winged arch
#

what is a data class

wet nexus
#

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

winged arch
#

ok is that associated with OOP ive heard alot about that

wet nexus
#

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

fathom rivet
#

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.

wet nexus
#

allows you to do stuff like

fathom rivet
#

Dataclasses let you define these more succinctly:

from dataclasses import dataclass
@dataclass
class BBox:
  ymin: int
  xmin: int
  ymax: int
  xmax: int
wet nexus
#

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
fathom rivet
#

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.

winged arch
#

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

fathom rivet
#

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.)

winged arch
#

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

#

?

fathom rivet
#

Yes.

winged arch
#

i am assuming so based on my knowledge

#

awesome thank you

#

for your time

opaque sinewBOT
#
Python help channel closed

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.