Azure-docs: Use existing tag and project on Python-sdk Custom Vision

Created on 13 Jun 2019  Â·  14Comments  Â·  Source: MicrosoftDocs/azure-docs

I noted on the python- sdk for the custom vision, I can only create new project and create new tag. Is there a way to use existing project and existing tag?
like changing the code: bus_stop_tag = trainer.create_tag(project_id, "")
project = trainer.create_project("Android App for Bus_Stop_Detection", domain_id=obj_detection_domain.id)?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

cognitive-servicesvc custom-visiosubsvc cxp product-question triaged

Most helpful comment

There are two ways to use existing projects or tags:

  1. Store the relevant ids for later use, i.e. project.id and bus_stop_tag.id, and then load and pass the stored value in to the call. For example if your project.id is "d6bef13c-f3cb-4784-9396-8cbf7f44acab" then you can write that to a file or hard coded it into your source. Then later pass that into the calls.
trainer.create_tag("d6bef13c-f3cb-4784-9396-8cbf7f44acab", "my new tag")
  1. Use the enumeration methods on the training client to look up, by name, the ids. To look up your project or tags here's a quick example from the other thread
project = next(filter(lambda p: p.name == "Android App for Bus_Stop_Detection", trainer.get_projects()), None)

if not project:
    print ("Couldn't find project")
    exit(-1)

bus_stop_tag = next(filter(lambda t: t.name == "bus stop", trainer.get_tags(project.id)), None)

if not bus_stop_tag:
    print ("Couldn't find tag")
    exit(-1)

All 14 comments

@ericjiang18 , Could you please provide the document you are referring to?

Thank you so much for helping :)

There are two ways to use existing projects or tags:

  1. Store the relevant ids for later use, i.e. project.id and bus_stop_tag.id, and then load and pass the stored value in to the call. For example if your project.id is "d6bef13c-f3cb-4784-9396-8cbf7f44acab" then you can write that to a file or hard coded it into your source. Then later pass that into the calls.
trainer.create_tag("d6bef13c-f3cb-4784-9396-8cbf7f44acab", "my new tag")
  1. Use the enumeration methods on the training client to look up, by name, the ids. To look up your project or tags here's a quick example from the other thread
project = next(filter(lambda p: p.name == "Android App for Bus_Stop_Detection", trainer.get_projects()), None)

if not project:
    print ("Couldn't find project")
    exit(-1)

bus_stop_tag = next(filter(lambda t: t.name == "bus stop", trainer.get_tags(project.id)), None)

if not bus_stop_tag:
    print ("Couldn't find tag")
    exit(-1)

ok got it! thanks

@ericjiang18 We will now proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.

I ran into error somehow

File "Training.py", line 39, in
bus_stop_tag = next(filter(lambda t: t.name == "postive", trainer.get_tags()), None)
TypeError: get_tags() missing 1 required positional argument: 'project_id'

@ram-msft

@ericjiang18 Sorry, I missed the arg in the snippet, will edit but it should be:

bus_stop_tag = next(filter(lambda t: t.name == "bus stop", trainer.get_tags(project.id)), None)

@areddish
I somehow got this error:
AttributeError: 'NoneType' object has no attribute 'id'

That’s the error you’d get if you don’t have project set to a valid project object.

@areddish i am pretty sure I have the project object, but still shows error

@areddish how can i set it?

@ericjiang18 Use the snipped above to set both, updated it and repasted here:

project = next(filter(lambda p: p.name == "Android App for Bus_Stop_Detection", trainer.get_projects()), None)

if not project:
    print ("Couldn't find project")
    exit(-1)

bus_stop_tag = next(filter(lambda t: t.name == "bus stop", trainer.get_tags(project.id)), None)

if not bus_stop_tag:
    print ("Couldn't find tag")
    exit(-1)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

JamesDLD picture JamesDLD  Â·  3Comments

jharbieh picture jharbieh  Â·  3Comments

Favna picture Favna  Â·  3Comments

JeffLoo-ong picture JeffLoo-ong  Â·  3Comments

ianpowell2017 picture ianpowell2017  Â·  3Comments