tensorflow / models

Models and examples built with TensorFlow
Other
76.95k stars 45.79k forks source link

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

Closed AndrewHartAR closed 4 years ago

AndrewHartAR commented 6 years ago

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 commented 6 years ago

chage tensorflow version to 1.5.0+

AndrewHartAR commented 6 years ago

@xiliu as I explained, I did.

hustc12 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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

aysark commented 6 years ago

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 commented 6 years ago

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

AliceDinh commented 6 years ago

@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 commented 6 years ago

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

AliceDinh commented 6 years ago

@doanthuansudo apt-get install python-matplotlib for installing matplotlibbut 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 commented 6 years ago

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

AliceDinh commented 6 years ago

@doanthuan fixed, I need to install from root

vanderlin commented 6 years ago

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 commented 6 years ago

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

basemdabbour commented 5 years ago

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 commented 4 years ago

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 commented 3 years ago

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