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

"AttributeError: 'module' object has no attribute 'data'" termination error when running Pets on Google Cloud tutorial #4058

Closed
AndrewHartAR opened this issue Apr 23, 2018 · 18 comments
Assignees

Comments

@AndrewHartAR
Copy link

I'm following the "Distributed Training on the Oxford-IIIT Pets Dataset on Google Cloud" tutorial.

Following the step of starting training, about 8 minutes later, I get a termination, with this error from the logs:

Termination reason: Error. Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main "main", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 167, in tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 163, in main worker_job_name, is_chief, FLAGS.train_dir) File "/root/.local/lib/python2.7/site-packages/object_detection/trainer.py", line 264, in train train_config.prefetch_queue_capacity, data_augmentation_options) File "/root/.local/lib/python2.7/site-packages/object_detection/trainer.py", line 59, in create_input_queue tensor_dict = create_tensor_dict_fn() File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 120, in get_next dataset_builder.build(config)).get_next() File "/root/.local/lib/python2.7/site-packages/object_detection/builders/dataset_builder.py", line 164, in build functools.partial(tf.data.TFRecordDataset, buffer_size=8 * 1000 * 1000), AttributeError: 'module' object has no attribute 'data' The replica worker 0 exited with a non-zero status of 1.

Googling this, I can't find any specific results, other than suggestions that the version of Python may be out of date. The tutorial gives the TensorFlow runtime version as 1.2, of which the options are 1.2, 1.4, 1.5 and 1.6. Changing to any of these other versions, I run into different errors, and I assume that isn't the correct solution.

@xiliu
Copy link

xiliu commented Apr 26, 2018

chage tensorflow version to 1.5.0+

@AndrewHartAR
Copy link
Author

@xiliu as I explained, I did.

@hustc12
Copy link

hustc12 commented Apr 27, 2018

I get this issue too, with tensorflow version 1.7. Tried version 1.5 but still meet this issue.
One thing I notice is that I also use the Python2.7, which is the same version as @ProjectDent used. I will use Python3 to have a try.

@JShep1
Copy link

JShep1 commented Apr 28, 2018

I get the same error with tf 1.7 and Python2.7. Tried pulling the most recent setup.py which was said to be updated - nothing changes when used. Any results on running with Python3? @huzq85

EDIT: I added Tensorflow and Jupyter to the required packages in the setup.py and it seemingly fixes the error. So my required packages line looks like this:
REQUIRED_PACKAGES = ['Tensorflow>=1.4.0','Pillow>=1.0','Matplotlib>=2.1','Cython>=0.28.1','Jupyter']

@hustc12
Copy link

hustc12 commented Apr 29, 2018

@JShep1, I've tried on Python3, but still meet this issue, however, your solution seems resolve this problem. I guess you can pull a request for this issue?

@vggl
Copy link

vggl commented May 7, 2018

@JShep1 you didn't do any additional change from the tutorial? Because I'm still unable to run it.

@aysark
Copy link
Contributor

aysark commented May 14, 2018

Thanks @JShep1 finally got it running now, after making your suggested edits to setup.py. I ran it on TF 1.5 with Python 2.7.

@doanthuan
Copy link

I have solved this issue by using --run-time 1.7. Thank you

@AliceDinh
Copy link

@doanthuan and @aysark I could not install Matplotlib>=2.1 and Cython>=0.28.1 on Ubuntu 16.04, I think that's reason why I got error: AttributeError: 'module' object has no attribute 'data'. Do you know how to install them, I did follow some suggestion of Google without success.

@doanthuan
Copy link

Hi @AliceDinh,
What is the command you have run to install them? And what is the error message you got?

@AliceDinh
Copy link

@doanthuan sudo apt-get install python-matplotlib for installing matplotlib but get 1.5.1 version and sudo apt-get install cython or pip install Cython fail

alicedinh@ubuntu:~/models$ sudo apt-get install Cython
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package Cython
alicedinh@ubuntu:~/models$ pip install cython
Collecting cython
  Using cached https://files.pythonhosted.org/packages/fe/d6/a097bd9913cc0fc974b968f5586d3f0609f46ca58b2aae3b8dfd51c1fe18/Cython-0.28.2-cp27-cp27mu-manylinux1_x86_64.whl
object-detection 0.1 has requirement Matplotlib>=2.1, but you'll have matplotlib 1.5.1 which is incompatible.
Installing collected packages: cython
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/cython.py'
Consider using the `--user` option or check the permissions.

@doanthuan
Copy link

let try to install with pip, ex: pip install matplotlib

@AliceDinh
Copy link

@doanthuan fixed, I need to install from root

@vanderlin
Copy link

Still getting this same error:

worker-replica-1
Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 184, in <module> tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 180, in main graph_hook_fn=graph_rewriter_fn) File "/root/.local/lib/python2.7/site-packages/object_detection/trainer.py", line 264, in train train_config.prefetch_queue_capacity, data_augmentation_options) File "/root/.local/lib/python2.7/site-packages/object_detection/trainer.py", line 59, in create_input_queue tensor_dict = create_tensor_dict_fn() File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 121, in get_next dataset_builder.build(config)).get_next() File "/root/.local/lib/python2.7/site-packages/object_detection/builders/dataset_builder.py", line 164, in build functools.partial(tf.data.TFRecordDataset, buffer_size=8 * 1000 * 1000), AttributeError: 'module' object has no attribute 'data'

I am running this:

gcloud ml-engine jobs submit training lotbot_car_db_detector_`date +%s` \
    --runtime-version 1.2 \
    --job-dir=gs://lotbot_car_db_detector/data \
    --packages dist/object_detection-0.1.tar.gz,slim/dist/slim-0.1.tar.gz \
    --module-name object_detection.train \
    --region us-central1 \
    --config object_detection/samples/cloud/cloud.yml \
    -- \
    --train_dir=gs://lotbot_car_db_detector/data \
    --pipeline_config_path=gs://lotbot_car_db_detector/data/ssd_mobilenet_v2_coco.config

my yml is:

trainingInput:
  runtimeVersion: "1.2"
  scaleTier: CUSTOM
  masterType: standard_gpu
  workerCount: 5
  workerType: standard_gpu
  parameterServerCount: 3
  parameterServerType: standard

@Devin-T
Copy link

Devin-T commented May 30, 2018

I get the issue too, with tensorflow 1.1 and python3.4. and I solved it by upgrade tensorflow to 1.8

@basemdabbour
Copy link

basemdabbour commented May 8, 2019

Anyone knows how to fix this kind of error : AttributeError: module 'cv2' has no attribute 'data' ?

I am doing face recognition with the following code inside py file ""face_capture.py:

import time
import sys
import os
import json
import logging
import argparse
import numpy as np
import cv2

sys.path.append(os.path.join(os.path.dirname(file), os.pardir))
from src.init import *

def generate_faces(saving_path, num):

#face_cascade = cv2.CascadeClassifier(config_parser['OPEN_CV']['cascade_classifier_path'])
#face_cascade = cv2.CascadeClassifier('/home/basem/Desktop/tenserflow1/facial_emotion_recognition__EMOJIFIER/haarcascade_frontalface_default.xml')
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")


if not os.path.exists(saving_path):
    os.makedirs(saving_path)

i = 0

while i < num:
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Operations on the frame
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # detect the faces, bounding boxes
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    # draw the rectangle (bounding-boxes)
    for (x,y,w,h) in faces:

        cv2.rectangle(frame, (x,y), (x+w, y+h), (255,0,0), 2)

        img_path = os.path.join(saving_path, '_' + str(time.time()) + '.png')
        cv2.imwrite(img_path, frame[y:y+h, x:x+w, :])

        logger.info('{i} path: {path} created'.format(i=i, path=img_path))
        i += 1

    cv2.imshow('faces', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

if name == 'main':

logger = logging.getLogger('emojifier.face_capture')

parser = argparse.ArgumentParser()

parser.add_argument(
    '-e', '--emotion_name',
    type=str,
    choices=EMOTION_MAP.keys(),
    help='Emotion class name for which to capture face-expression.',
    required=True
)
parser.add_argument(
    '-n', '--number_of_images',
    type=int,
    help='Number of images to capture for the given emotion.',
    required=True
)

args = parser.parse_args()

EMOTION_CLASS = args.emotion_name
N = args.number_of_images

cap = cv2.VideoCapture(0)

PATH = os.path.join(os.path.dirname(__file__), os.pardir, 'images', EMOTION_CLASS)

generate_faces(PATH, N)

and apply this command to execute the code to take 200 images to train the model with smile expression for example:
python3 src/face_capture.py --emotion_name smile --number_of_images 200

I have installed all dependencies [Tensorflow gpu 1.13, tensorflow, matplotlib, cython, opencv2, python3, python2.7 ...], but I am still getting the same error in all ways with python3 and 2.7!.

@tensorflowbutler
Copy link
Member

Hi There,
We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing.
If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.

@Mariela1817
Copy link

Traceback (most recent call last):
File "guardardatos.py", line 8, in
faceClassif= cv2.CascadeClassifier(cv2.data.Haarcascades+'haarcascade_frontalface_default.xml')
AttributeError: 'module' object has no attribute 'data'
help me

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