# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras
# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
import os
import cv2
print(tf.__version__)
DATADIR ="D:\Datasetes\legen"
CATEGORIES = ['light']
for category in CATEGORIES:
path = os.path.join(DATADIR,category) #to create a path to the image in our drive
for img in os.listdir(path):
img_array = cv2.imread(os.path.join(path,img),cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array , cmap="gray")
plt.show
plt.figure()
plt.imshow(img_array)
plt.colorbar()
plt.grid(False)
plt.show()
break
break
class_names = ['light', 'power', 'capture']
train_images.shape
len(train_labels)
train_labels
train_images = train_images / 255.0
train_labels = train_labels / 255.0
test_images = test_images / 255.0
test_labels = test_labels / 255.0
def class_names():
for category in CATEGORIES:
path = os.path.join(DATADIR,category)
class_names = CATEGORIES.index(category)
for img in (os.listdir(path)):
try:
img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE) # convert to array
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE)) # resize to normalize data size
training_data.append([new_array, class_num])
except Exception as e:
pass
import random
random.shuffle(training_data)
img_array = cv2.imread(os.path.join(path,img),cv2.IMREAD_GRAYSCALE)
plt.figure(figsize=(10,10))
for i in range(10):
plt.subplot(5,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(img_array, cmap='gray')
plt.xlabel(class_names(train_labels))
plt.show()
break
TypeError Traceback (most recent call last)
<ipython-input-147-400073625620> in <module>
29 plt.grid(False)
30 plt.imshow(img_array, cmap='gray')
---> 31 plt.xlabel(class_names(train_labels))
32 plt.show()
33 break
TypeError: class_names() takes 0 positional arguments but 1 was given
this is the code that I am using and it keeps on giving an error as ''function' object is not subscriptable.I have added the whole code into this. please help as this is a school project and it is included in my goddamn GPA the error happens in the line with :the last part of the code