How to solve 'import pycocotools._mask is not a valid win32 application' in tensorflow 1.13.1 and python 3.7?

Question:

I’m using object detection raccoon by datitran(https://github.com/datitran/raccoon_dataset) to train my own dataset and met an issue.

Environment Info.:

OS:Windows 10 64bit

CUDA and CUDNN: CUDA 10/CUDNN 7.5.0

Tensorflow version:1.13.1(GPU)

Python version:3.7.0 64 bit (Anaconda, Inc. on win32)

Model:ssd_mobilenet_v1_coco

Issue:

I want to start trainning by

python model_main.py 
--pipeline_config_path=Z:/Train/ssd_mobilenet_v1_coco_ship.config 
--model_dir=Z:/Train/train 
--alsologtostderr

and met an error

    Traceback (most recent call last):
  File "model_main.py", line 26, in <module>
    from object_detection import model_lib
  File "D:AnacondaenvstensorflowLibmodelsresearchobject_detectionmodel_lib.py", line 27, in <module>
    from object_detection import eval_util
  File "D:AnacondaenvstensorflowLibmodelsresearchobject_detectioneval_util.py", line 27, in <module>
    from object_detection.metrics import coco_evaluation
  File "D:AnacondaenvstensorflowLibmodelsresearchobject_detectionmetricscoco_evaluation.py", line 20, in <module>
    from object_detection.metrics import coco_tools
  File "D:AnacondaenvstensorflowLibmodelsresearchobject_detectionmetricscoco_tools.py", line 47, in <module>
    from pycocotools import coco
  File "D:Anacondaenvstensorflowlibsite-packagespycocotoolscoco.py", line 56, in <module>
    from . import mask as maskUtils
  File "D:Anacondaenvstensorflowlibsite-packagespycocotoolsmask.py", line 3, in <module>
    import pycocotools._mask as _mask
ImportError: DLL load failed: %1 is not a valid Win32 application.

Besides, I also tried old version command train.py in ~researchobject_detectionlegacyby

python train.py 
--logtostderr 
--pipeline_config_path=Z:/Train/ssd_mobilenet_v1_coco_ship.config  
--train_dir=Z:/Train/train

but it also failed to work:

WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.

WARNING:tensorflow:From D:Anacondaenvstensorflowlibsite-packagestensorflowpythonplatformapp.py:125: main (from __main__) is deprecated and will be removed in a future version.
Instructions for updating:
Use object_detection/model_main.py.
WARNING:tensorflow:From D:AnacondaenvstensorflowLibmodelsresearchobject_detectionlegacytrainer.py:266: create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.create_global_step
WARNING:tensorflow:From D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkop_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:num_readers has been reduced to 1 to match input file shards.
WARNING:tensorflow:From D:AnacondaenvstensorflowLibmodelsresearchobject_detectionbuildersdataset_builder.py:80: parallel_interleave (from tensorflow.contrib.data.python.ops.interleave_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.experimental.parallel_interleave(...)`.
Traceback (most recent call last):
  File "train.py", line 186, in <module>
    tf.app.run()
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonplatformapp.py", line 125, in run
    _sys.exit(main(argv))
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonutildeprecation.py", line 324, in new_func
    return func(*args, **kwargs)
  File "train.py", line 182, in main
    graph_hook_fn=graph_rewriter_fn)
  File "D:AnacondaenvstensorflowLibmodelsresearchobject_detectionlegacytrainer.py", line 280, in train
    train_config.prefetch_queue_capacity, data_augmentation_options)
  File "D:AnacondaenvstensorflowLibmodelsresearchobject_detectionlegacytrainer.py", line 59, in create_input_queue
    tensor_dict = create_tensor_dict_fn()
  File "train.py", line 123, in get_next
    dataset_builder.build(config)).get_next()
  File "D:AnacondaenvstensorflowLibmodelsresearchobject_detectionbuildersdataset_builder.py", line 134, in build
    config.input_path[:], input_reader_config)
  File "D:AnacondaenvstensorflowLibmodelsresearchobject_detectionbuildersdataset_builder.py", line 80, in read_dataset
    sloppy=config.shuffle))
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsdataset_ops.py", line 1605, in apply
    return DatasetV1Adapter(super(DatasetV1, self).apply(transformation_func))
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsdataset_ops.py", line 1127, in apply
    dataset = transformation_func(self)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataexperimentalopsinterleave_ops.py", line 88, in _apply_fn
    buffer_output_elements, prefetch_input_elements)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsreaders.py", line 133, in __init__
    cycle_length, block_length)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsdataset_ops.py", line 2827, in __init__
    super(InterleaveDataset, self).__init__(input_dataset, map_func)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsdataset_ops.py", line 2798, in __init__
    map_func, self._transformation_name(), dataset=input_dataset)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsdataset_ops.py", line 2124, in __init__
    self._function.add_to_graph(ops.get_default_graph())
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkfunction.py", line 490, in add_to_graph
    self._create_definition_if_needed()
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkfunction.py", line 341, in _create_definition_if_needed
    self._create_definition_if_needed_impl()
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkfunction.py", line 355, in _create_definition_if_needed_impl
    whitelisted_stateful_ops=self._whitelisted_stateful_ops)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkfunction.py", line 883, in func_graph_from_py_func
    outputs = func(*func_graph.inputs)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsdataset_ops.py", line 2099, in tf_data_structured_function_wrapper
    ret = func(*nested_args)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsreaders.py", line 247, in __init__
    filenames, compression_type, buffer_size, num_parallel_reads)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsreaders.py", line 212, in __init__
    self._impl = filenames.flat_map(read_one_file)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsdataset_ops.py", line 1005, in flat_map
    return FlatMapDataset(self, map_func)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsdataset_ops.py", line 2798, in __init__
    map_func, self._transformation_name(), dataset=input_dataset)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsdataset_ops.py", line 2124, in __init__
    self._function.add_to_graph(ops.get_default_graph())
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkfunction.py", line 490, in add_to_graph
    self._create_definition_if_needed()
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkfunction.py", line 341, in _create_definition_if_needed
    self._create_definition_if_needed_impl()
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkfunction.py", line 355, in _create_definition_if_needed_impl
    whitelisted_stateful_ops=self._whitelisted_stateful_ops)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkfunction.py", line 883, in func_graph_from_py_func
    outputs = func(*func_graph.inputs)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsdataset_ops.py", line 2099, in tf_data_structured_function_wrapper
    ret = func(*nested_args)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsreaders.py", line 209, in read_one_file
    return _TFRecordDataset(filename, compression_type, buffer_size)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondataopsreaders.py", line 111, in __init__
    argument_dtype=dtypes.string)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythondatautilconvert.py", line 35, in optional_param_to_tensor
    argument_default, dtype=argument_dtype, name=argument_name)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkconstant_op.py", line 245, in constant
    allow_broadcast=True)
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworkconstant_op.py", line 283, in _constant_impl
    allow_broadcast=allow_broadcast))
  File "D:Anacondaenvstensorflowlibsite-packagestensorflowpythonframeworktensor_util.py", line 501, in make_tensor_proto
    (dtype, nparray.dtype, values))
TypeError: Incompatible types: <dtype: 'string'> vs. object. Value is

What should I do to make any of them work?

Asked By: ElShaddollWinda

||

Answers:

you need to instal VİSUAL C++ 2015 for pycocotools but when i install visual c++ it wont work. than i edit pycocotools for using wait a moment im loading it github

edit: loaded https://github.com/rifatalptekincetin/pycocotools-edited

download pycocotools folder replace it to research/object_detection file path must be:

models-master/resarch/object_detection/pycocotools/__init__.py #etc.

There is at least one an incompatibility between Python 3 and pycocotools that also generated a pull request at GitHub. One of them is:

Python 2 and 3

For more info, access:

Pull Request for pycocotools library

Answered By: razimbres

Hey for anyone using windows for me this actually worked.

1) Install Visual C++ 2015 Build Tools from https://go.microsoft.com/fwlink/?LinkId=691126 with the default selection.

2) Go to C:Program Files (x86)Microsoft Visual C++ Build Tools and run vcbuildtools_msbuild.bat

3)Then in Anaconda copy and run this (you have to have installed git … if not just use pip install git)

pip install

git+https://github.com/philferriere/cocoapi.git#egg=pycocotools^&subdirectory=PythonAPI

Hope it works for you too 🙂

Answered By: Ngugi John

Or you can use decode/encode Python functions as a translation from C original api.

https://github.com/armengot/COCOtoolsFORK

Answered By: Marcelo Armengot
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.