ammarchalifah / people-tracker-and-counter

Python based object detection and tracking for collecting data from CCTV. Built on TensorFlow Object Detection API 2 and centroid tracker implementation by Pyimagesearch.
6 stars 1 forks source link

ImportError: cannot import name 'center_net_hourglass_feature_extractor #1

Closed andreqwert closed 4 years ago

andreqwert commented 4 years ago

Hello, Thanks for sharing your code! I tried to launch your repo with the efficientdet model provided in additional requirements. All the described steps in README were completed but I got the following error: ModuleNotFoundError: No module named 'object_detection.models'. After that I made a replacement in a way that directory models was in directory object_detection. Since I have the error: ImportError: cannot import name 'center_net_hourglass_feature_extractor'. Could you please describe how can I solve this problem to launch the script?

ammarchalifah commented 4 years ago

Hi! Thanks for trying my code out! I'll try my best to solve the issue.

the models directory which stores the pretrained object detection models is different to object_detection.models. My directory tree structure looks like this:

Folder PATH listing
Volume serial number is DA74-F750
F:.
ÃÄÄÄ.dist
ÃÄÄÄ.idea
³   ÀÄÄÄinspectionProfiles
ÃÄÄÄ.vscode
ÃÄÄÄasset
ÃÄÄÄfunctions
³   ÀÄÄÄ__pycache__
ÃÄÄÄlabel
ÃÄÄÄmodels
³   ÃÄÄÄcenternet_hg104_1024x1024_kpts_coco17_tpu-32
³   ³   ÃÄÄÄcheckpoint
³   ³   ÀÄÄÄsaved_model
³   ³       ÀÄÄÄvariables
³   ÃÄÄÄefficientdet_d0_coco17_tpu-32
³   ³   ÃÄÄÄcheckpoint
³   ³   ÀÄÄÄsaved_model
³   ³       ÃÄÄÄassets
³   ³       ÀÄÄÄvariables
³   ÃÄÄÄfaster_rcnn_inception_resnet_v2_1024x1024_coco17_tpu-8
³   ³   ÃÄÄÄcheckpoint
³   ³   ÀÄÄÄsaved_model
³   ³       ÀÄÄÄvariables
³   ÃÄÄÄfaster_rcnn_resnet101_v1_1024x1024_coco17_tpu-8
³   ³   ÃÄÄÄcheckpoint
³   ³   ÀÄÄÄsaved_model
³   ³       ÀÄÄÄvariables
³   ÃÄÄÄfaster_rcnn_resnet50_coco_2018_01_28
³   ³   ÀÄÄÄsaved_model
³   ³       ÀÄÄÄvariables
³   ÃÄÄÄssd_inception_v2_coco_2017_11_17
³   ÃÄÄÄssd_mobilenet_v1_ppn_2018_07_03
³   ³   ÀÄÄÄsaved_model
³   ³       ÀÄÄÄvariables
³   ÃÄÄÄssd_mobilenet_v2_fpnlite_320x320_coco17_tpu-8
³   ³   ÃÄÄÄcheckpoint
³   ³   ÀÄÄÄsaved_model
³   ³       ÀÄÄÄvariables
³   ÀÄÄÄssd_resnet50_v1_fpn_640x640_coco17_tpu-8
³       ÃÄÄÄcheckpoint
³       ÀÄÄÄsaved_model
³           ÃÄÄÄassets
³           ÀÄÄÄvariables
ÃÄÄÄobject_detection
³   ÃÄÄÄanchor_generators
³   ³   ÀÄÄÄ__pycache__
³   ÃÄÄÄbox_coders
³   ³   ÀÄÄÄ__pycache__
³   ÃÄÄÄbuilders
³   ³   ÀÄÄÄ__pycache__
³   ÃÄÄÄcolab_tutorials
³   ÃÄÄÄconfigs
³   ³   ÀÄÄÄtf2
³   ÃÄÄÄcore
³   ³   ÀÄÄÄ__pycache__
³   ÃÄÄÄdata
³   ÃÄÄÄdataset_tools
³   ³   ÃÄÄÄcontext_rcnn
³   ³   ÀÄÄÄdensepose
³   ÃÄÄÄdata_decoders
³   ÃÄÄÄdockerfiles
³   ³   ÃÄÄÄandroid
³   ³   ÃÄÄÄtf1
³   ³   ÀÄÄÄtf2
³   ÃÄÄÄg3doc
³   ³   ÀÄÄÄimg
³   ÃÄÄÄinference
³   ÃÄÄÄlegacy
³   ÃÄÄÄmatchers
³   ³   ÀÄÄÄ__pycache__
³   ÃÄÄÄmeta_architectures
³   ³   ÀÄÄÄ__pycache__
³   ÃÄÄÄmetrics
³   ÃÄÄÄmodels
³   ³   ÃÄÄÄkeras_models
³   ³   ³   ÃÄÄÄbase_models
³   ³   ³   ÀÄÄÄ__pycache__
³   ³   ÀÄÄÄ__pycache__
³   ÃÄÄÄpackages
³   ³   ÃÄÄÄtf1
³   ³   ÀÄÄÄtf2
³   ÃÄÄÄpredictors
³   ³   ÃÄÄÄheads
³   ³   ³   ÀÄÄÄ__pycache__
³   ³   ÀÄÄÄ__pycache__
³   ÃÄÄÄprotos
³   ³   ÀÄÄÄ__pycache__
³   ÃÄÄÄsamples
³   ³   ÃÄÄÄcloud
³   ³   ÀÄÄÄconfigs
³   ÃÄÄÄtest_data
³   ÃÄÄÄtest_images
³   ³   ÃÄÄÄducky
³   ³   ³   ÃÄÄÄtest
³   ³   ³   ÀÄÄÄtrain
³   ³   ÀÄÄÄsnapshot_serengeti
³   ÃÄÄÄtpu_exporters
³   ³   ÀÄÄÄtestdata
³   ³       ÃÄÄÄfaster_rcnn
³   ³       ÀÄÄÄssd
³   ÃÄÄÄutils
³   ³   ÀÄÄÄ__pycache__
³   ÀÄÄÄ__pycache__
ÃÄÄÄofficial
³   ÃÄÄÄbenchmark
³   ³   ÃÄÄÄdatastore
³   ³   ³   ÀÄÄÄschema
³   ³   ÀÄÄÄmodels
³   ³       ÀÄÄÄshakespeare
³   ÃÄÄÄcolab
³   ³   ÀÄÄÄnlp
³   ÃÄÄÄcore
³   ÃÄÄÄmodeling
³   ³   ÃÄÄÄactivations
³   ³   ³   ÀÄÄÄ__pycache__
³   ³   ÃÄÄÄhyperparams
³   ³   ³   ÀÄÄÄ__pycache__
³   ³   ÃÄÄÄoptimization
³   ³   ³   ÀÄÄÄconfigs
³   ³   ÃÄÄÄtraining
³   ³   ÀÄÄÄ__pycache__
³   ÃÄÄÄnlp
³   ³   ÃÄÄÄalbert
³   ³   ÃÄÄÄbert
³   ³   ÃÄÄÄconfigs
³   ³   ÃÄÄÄdata
³   ³   ÃÄÄÄmodeling
³   ³   ³   ÃÄÄÄlayers
³   ³   ³   ÃÄÄÄlosses
³   ³   ³   ÃÄÄÄmodels
³   ³   ³   ÃÄÄÄnetworks
³   ³   ³   ÀÄÄÄops
³   ³   ÃÄÄÄnhnet
³   ³   ³   ÀÄÄÄtestdata
³   ³   ³       ÀÄÄÄcrawled_articles
³   ³   ³           ÃÄÄÄdomain_0.com
³   ³   ³           ÀÄÄÄdomain_1.com
³   ³   ÃÄÄÄtasks
³   ³   ÃÄÄÄtransformer
³   ³   ³   ÀÄÄÄutils
³   ³   ÀÄÄÄxlnet
³   ÃÄÄÄpip_package
³   ÃÄÄÄrecommendation
³   ÃÄÄÄstaging
³   ³   ÀÄÄÄtraining
³   ÃÄÄÄutils
³   ³   ÃÄÄÄflags
³   ³   ÃÄÄÄmisc
³   ³   ÀÄÄÄtesting
³   ³       ÀÄÄÄscripts
³   ÃÄÄÄvision
³   ³   ÃÄÄÄdetection
³   ³   ³   ÃÄÄÄconfigs
³   ³   ³   ÃÄÄÄdataloader
³   ³   ³   ÃÄÄÄevaluation
³   ³   ³   ÃÄÄÄexecutor
³   ³   ³   ÃÄÄÄmodeling
³   ³   ³   ³   ÀÄÄÄarchitecture
³   ³   ³   ÃÄÄÄops
³   ³   ³   ÀÄÄÄutils
³   ³   ³       ÀÄÄÄobject_detection
³   ³   ÃÄÄÄimage_classification
³   ³   ³   ÃÄÄÄconfigs
³   ³   ³   ³   ÀÄÄÄexamples
³   ³   ³   ³       ÃÄÄÄefficientnet
³   ³   ³   ³       ³   ÀÄÄÄimagenet
³   ³   ³   ³       ÀÄÄÄresnet
³   ³   ³   ³           ÀÄÄÄimagenet
³   ³   ³   ÃÄÄÄefficientnet
³   ³   ³   ³   ÀÄÄÄ__pycache__
³   ³   ³   ÃÄÄÄresnet
³   ³   ³   ÀÄÄÄ__pycache__
³   ³   ÀÄÄÄ__pycache__
³   ÀÄÄÄ__pycache__
ÃÄÄÄvideos
ÀÄÄÄ__pycache__

I don't really know the cause now, but maybe you can try this:

  1. remove object_detection and official folder from people-tracker-and-counter. Then go to TensorFlow 2 Object Detection API and install their environment on another directory. Follow the instructions here
  2. Copy object_detection from models/research and official from models in TF2 project directory, then paste it under people-tracker-and-counter.
  3. Try to relaunch the program.

If the problem still persists, do you mind to copy the error log, line, and the code in the problematic line? I'll try to think the solution as soon as possible. Thank you!

ammarchalifah commented 4 years ago

Oh, one more thing. Could to send me the directory tree structure of your project? I haven't tested this on different computer so I'm curious about it.

andreqwert commented 4 years ago

Now it works! Thanks a lot!

tree -d -L 3 shows:

├── __pycache__
├── asset
├── functions
│   └── __pycache__
├── label
├── models
│   ├── community
│   ├── efficientdet_d0_coco17_tpu-32
│   │   ├── checkpoint
│   │   └── saved_model
│   ├── orbit
│   └── research
│       ├── a3c_blogpost
│       ├── adversarial_text
│       ├── attention_ocr
│       ├── audioset
│       ├── autoaugment
│       ├── cognitive_planning
│       ├── cvt_text
│       ├── deep_speech
│       ├── deeplab
│       ├── delf
│       ├── efficient-hrl
│       ├── lfads
│       ├── lstm_object_detection
│       ├── marco
│       ├── nst_blogpost
│       ├── pcl_rl
│       ├── rebar
│       ├── slim
│       └── vid2depth
├── object_detection
│   ├── __pycache__
│   ├── anchor_generators
│   │   └── __pycache__
│   ├── box_coders
│   │   └── __pycache__
│   ├── builders
│   │   └── __pycache__
│   ├── colab_tutorials
│   ├── configs
│   │   └── tf2
│   ├── core
│   │   └── __pycache__
│   ├── data
│   ├── data_decoders
│   ├── dataset_tools
│   │   ├── context_rcnn
│   │   └── densepose
│   ├── dockerfiles
│   │   ├── android
│   │   ├── tf1
│   │   └── tf2
│   ├── g3doc
│   │   └── img
│   ├── inference
│   ├── legacy
│   ├── matchers
│   │   └── __pycache__
│   ├── meta_architectures
│   │   └── __pycache__
│   ├── metrics
│   ├── models
│   │   ├── __pycache__
│   │   └── keras_models
│   ├── packages
│   │   ├── tf1
│   │   └── tf2
│   ├── predictors
│   │   ├── __pycache__
│   │   └── heads
│   ├── protos
│   │   └── __pycache__
│   ├── samples
│   │   ├── cloud
│   │   └── configs
│   ├── test_data
│   ├── test_images
│   │   ├── ducky
│   │   └── snapshot_serengeti
│   ├── tpu_exporters
│   │   └── testdata
│   └── utils
│       └── __pycache__
├── official
│   ├── __pycache__
│   ├── colab
│   │   └── nlp
│   ├── core
│   ├── modeling
│   │   ├── __pycache__
│   │   ├── activations
│   │   ├── hyperparams
│   │   ├── optimization
│   │   └── training
│   ├── nlp
│   │   ├── albert
│   │   ├── bert
│   │   ├── configs
│   │   ├── data
│   │   ├── modeling
│   │   ├── nhnet
│   │   ├── tasks
│   │   ├── transformer
│   │   └── xlnet
│   ├── pip_package
│   ├── recommendation
│   ├── staging
│   │   └── training
│   ├── utils
│   │   ├── flags
│   │   ├── misc
│   │   └── testing
│   └── vision
│       ├── __pycache__
│       ├── detection
│       └── image_classification
└── videos

I work under Ubuntu 18.01 x64