1

I am trying to follow these instructions in order to train tensorflow: https://www.datacamp.com/community/tutorials/tensorflow-tutorial?utm_source=adwords_ppc&utm_campaignid=898687156&utm_adgroupid=48947256715&utm_device=c&utm_keyword=&utm_matchtype=b&utm_network=g&utm_adpostion=1t1&utm_creative=255798340456&utm_targetid=dsa-498578051924&utm_loc_interest_ms=&utm_loc_physical_ms=9061578&gclid=Cj0KCQiA5dPuBRCrARIsAJL7oeh8O1BawcnisHgACgu2gxP1BcofUPxNxsMf2D7cOjC-7QYeuU3ZBZEaAuDnEALw_wcB

I execute this code:

import os
import numpy as np

def load_data(data_directory):
    directories = [d for d in os.listdir(data_directory)
            if os.path.isdir(os.path.join(data_directory, d))]

    labels = []
    images = []
    for d in directories:
        label_directory = os.path.join(data_directory,d)
        file_names = [os.path.join(label_directory, f)
                for f in os.listdir(label_directory)
                if f.endswith(".ppm")]
        for f in file_names:
            images.append(skimage.data.imread(f))
            labels.append(int(d))
    return images, labels

ROOT_PATH = "/home/"
train_data_directory = os.path.join(ROOT_PATH, "BelgiumTSC_Training/Training")
test_data_directory = os.path.join(ROOT_PATH, "BelgiumTSC_Testing/Testing")

images, labels = load_data(train_data_directory)

# print the 'images' dimensions
print(np.array(images).ndim)

# print the number of 'images''s elements
print(np.array(images).size)

# print the first instance of 'images'
images[0]

I get this error:

Traceback (most recent call last):
  File "loading_data.py", line 24, in <module>
    images, labels = load_data(train_data_directory)
  File "loading_data.py", line 16, in load_data
    images.append(skimage.data.imread(f))
NameError: name 'skimage' is not defined

I followed this link without any success: Import error No module named skimage

Progman
  • 16,827
  • 6
  • 33
  • 48
just_learning
  • 413
  • 2
  • 11
  • 24
  • 1
    It looks like you need to import `scikit-image` with `import skimage`. If scikit-image is not installed, you can install it with pip or conda (see https://scikit-image.org/docs/stable/install.html) – Emmanuelle Gouillart Nov 20 '19 at 20:46
  • I did the `import skimage` now I get: `Traceback (most recent call last): File "loading_data.py", line 25, in images, labels = load_data(train_data_directory) File "loading_data.py", line 17, in load_data images.append(skimage.data.imread(f)) AttributeError: module 'skimage.data' has no attribute 'imread'` – just_learning Nov 20 '19 at 20:55
  • 2
    It's `skimage.io.imread`, the tutorial might have typos. – Emmanuelle Gouillart Nov 20 '19 at 21:33
  • Because I am very new, is tensorflow a DNN that I only train it with input pictures? Can I configure it? What can I change in tensorflow? For example can I configure the internal stages and the weights of its neurons? – just_learning Nov 25 '19 at 14:06
  • `1 4575 Traceback (most recent call last): File "loading_data.py", line 38, in print(labels.ndim) AttributeError: 'list' object has no attribute 'ndim'` What is this error? – just_learning Nov 26 '19 at 18:43

1 Answers1

0

instead of

images.append(skimage.data.imread(f))

use

import cv2
images.append(cv2.imread(f))
kesh
  • 4,515
  • 2
  • 12
  • 20
Katty_P
  • 11
  • 1