Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'pycococreatortools' is not defined #35

Open
anmspro opened this issue Jul 2, 2020 · 2 comments
Open

NameError: name 'pycococreatortools' is not defined #35

anmspro opened this issue Jul 2, 2020 · 2 comments

Comments

@anmspro
Copy link

anmspro commented Jul 2, 2020

I have installed using this:

!pip install cython
!pip install git+git://github.com/waspinator/[email protected]

But still I got this error. Whole code:

INFO = {
    "description": "Fashion Dataset",
    "url": "https://github.com/waspinator/pycococreator",
    "version": "0.1.0",
    "year": 2020,
    "contributor": "Abu Noman Md. Sakib",
    "date_created": datetime.datetime.utcnow().isoformat(' ')
}

LICENSES = [
    {
        "id": 1,
        "name": "GB",
        "url": "GB"
    }
]

CATEGORIES = [
    {
        'id': 1,
        'name': 'mask',
        'supercategory': 'fashion',
    }
]

coco_output = {
    "info": INFO,
    "licenses": LICENSES,
    "categories": CATEGORIES,
    "images": [],
    "annotations": []
}

image_id = 1
segmentation_id = 1

ROOT_DIR = "train"
IMAGE_DIR = "train/images"
ANNOTATION_DIR = "train/annotations"

image_files = [f for f in listdir(IMAGE_DIR) if isfile(join(IMAGE_DIR, f))]
annotation_files = [f for f in listdir(ANNOTATION_DIR) if isfile(join(ANNOTATION_DIR, f))]

# go through each image
for image_filename in image_files:
    image = Image.open(IMAGE_DIR + '/' + image_filename)
    image_info = pycococreatortools.create_image_info(image_id, os.path.basename(image_filename), image.size)

    coco_output["images"].append(image_info)

# go through each associated annotation
for annotation_filename in annotation_files:

    print(annotation_filename)
    class_id = [x['id'] for x in CATEGORIES if x['name'] in annotation_filename][0]
    category_info = {'id': class_id, 'is_crowd': 'crowd' in image_filename}
    binary_mask = np.asarray(Image.open(annotation_filename).convert('1')).astype(np.uint8)

    annotation_info = pycococreatortools.create_annotation_info(segmentation_id, image_id, category_info, binary_mask, image.size, tolerance=2)

    if annotation_info is not None:
        coco_output["annotations"].append(annotation_info)

    segmentation_id = segmentation_id + 1

    image_id = image_id + 1

with open('train/images.json', 'w') as output_json_file:
    json.dump(coco_output, output_json_file)
    

I still don't know if the code works or not. Please help!

@colt18
Copy link

colt18 commented Jul 2, 2020

Same here. pycococreatortools is 2 levels above shapes and it seems it has not been installed properly.

Edit: My bad. On the root folder run python setup.py install to install packages. It works now.
Swtich to root folder and then "pip install .". Never use setup.py install.

@anmspro
Copy link
Author

anmspro commented Jul 3, 2020

@colt18 I have done as you said. Then imported the module as import pycococreatortools. But I still getting a error:

AttributeError: module 'pycococreatortools' has no attribute 'create_image_info'

Do you have any suggestions?

Solved: used from pycococreatortools import pycococreatortools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants