1

I don't know whats going really going on here, I want it to print (answer) but stopped prematurely. https://colab.research.google.com/drive/1hvHkDusyqEsdZg5ZRVhhriZrDagpFdU6?usp=sharing

import os 
import warnings 
from zipfile import ZipFile 
import random
from shutil import copyfile
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.image import imread
import pathlib
import tensorflow as tf 
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, 
Dense, Dropout
from tensorflow.keras.models import Sequential
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint 
import pandas as pd
import numpy as np
!pip install keras --upgrade
from keras_preprocessing.image import load_img, img_to_array
file_name = "/content/dermnet.zip"
with ZipFile(file_name,'r') as zip: 
 zip.extractall()
 print('done')

#Make new directory 
original_dataset_dir = '/content/dataset'
base_dir = '/content/skin-data/'
os.mkdir(base_dir) 
#create two folders (train and validation)
train_dir = os.path.join(base_dir, 'train')
os.mkdir(train_dir)

validation_dir = os.path.join(base_dir, 'validation')
os.mkdir(validation_dir)
 
#Under train folder create folders 


train_Acne_and_Rosacea_dir = os.path.join(train_dir, 'Acne and Rosacea Photos')
os.mkdir(train_Acne_and_Rosacea_dir)

train_Vascular_Tumors_dir = os.path.join(train_dir, 'Vascular Tumors')
os.mkdir(train_Vascular_Tumors_dir)

train_Exanthems_and_Drug_Eruption_dir = os.path.join(train_dir, 'Exanthems and Drug Eruptions')
os.mkdir(train_Exanthems_and_Drug_Eruption_dir)

train_Systemic_Disease_dir = os.path.join(train_dir, 'Systemic Disease')
os.mkdir(train_Systemic_Disease_dir)

train_Light_Diseases_and_Disorders_of_Pigmentation_dir = os.path.join(train_dir, 'Light Diseases and Disorders of Pigmentation')
os.mkdir(train_Light_Diseases_and_Disorders_of_Pigmentation_dir)

train_Melanoma_Skin_Cancer_Nevi_and_Moles_dir = os.path.join(train_dir, 'Melanoma Skin Cancer Nevi and Moles')
os.mkdir(train_Melanoma_Skin_Cancer_Nevi_and_Moles_dir)

train_Urticaria_Hives_dir = os.path.join(train_dir, 'Urticaria Hives')
os.mkdir(train_Urticaria_Hives_dir)

train_Hair_Loss_Photos_Alopecia_and_other_Hair_Diseases_dir = os.path.join(train_dir, 'Hair Loss Photos Alopecia and other Hair Diseases')
os.mkdir(train_Hair_Loss_Photos_Alopecia_and_other_Hair_Diseases_dir)

train_Scabies_Lyme_Disease_and_other_Infestations_and_Bites_dir = os.path.join(train_dir, 'Scabies Lyme Disease and other Infestations and Bites')
os.mkdir(train_Scabies_Lyme_Disease_and_other_Infestations_and_Bites_dir)

train_Psoriasis_pictures_Lichen_Planus_and_related_diseases_dir = os.path.join(train_dir, 'Psoriasis pictures Lichen Planus and related diseases')
os.mkdir(train_Psoriasis_pictures_Lichen_Planus_and_related_diseases_dir)

train_Seborrheic_Keratoses_and_other_Benign_Tumors_dir = os.path.join(train_dir, 'Seborrheic Keratoses and other Benign Tumors')
os.mkdir(train_Seborrheic_Keratoses_and_other_Benign_Tumors_dir)



#Under validation folder createfolders 

validation_Acne_and_Rosacea_dir = os.path.join(validation_dir, 'Acne and Rosacea Photos')
os.mkdir(validation_Acne_and_Rosacea_dir)

validation_Vascular_Tumors_dir = os.path.join(validation_dir, 'Vascular Tumors')
os.mkdir(validation_Vascular_Tumors_dir)

validation_Exanthems_and_Drug_Eruption_dir = os.path.join(validation_dir, 'Exanthems and Drug Eruptions')
os.mkdir(validation_Exanthems_and_Drug_Eruption_dir)

validation_Systemic_Disease_dir = os.path.join(validation_dir, 'Systemic Disease')
os.mkdir(validation_Systemic_Disease_dir)

validation_Light_Diseases_and_Disorders_of_Pigmentation_dir = os.path.join(validation_dir, 'Light Diseases and Disorders of Pigmentation')
os.mkdir(validation_Light_Diseases_and_Disorders_of_Pigmentation_dir)

validation_Melanoma_Skin_Cancer_Nevi_and_Moles_dir = os.path.join(validation_dir, 'Melanoma Skin Cancer Nevi and Moles')
os.mkdir(validation_Melanoma_Skin_Cancer_Nevi_and_Moles_dir)

validation_Urticaria_Hives_dir = os.path.join(validation_dir, 'Urticaria Hives')
os.mkdir(validation_Urticaria_Hives_dir)

validation_Hair_Loss_Photos_Alopecia_and_other_Hair_Diseases_dir = os.path.join(validation_dir, 'Hair Loss Photos Alopecia and other Hair Diseases')
os.mkdir(validation_Hair_Loss_Photos_Alopecia_and_other_Hair_Diseases_dir)

validation_Scabies_Lyme_Disease_and_other_Infestations_and_Bites_dir = os.path.join(validation_dir, 'Scabies Lyme Disease and other Infestations and Bites')
os.mkdir(validation_Scabies_Lyme_Disease_and_other_Infestations_and_Bites_dir)

validation_Psoriasis_pictures_Lichen_Planus_and_related_diseases_dir = os.path.join(validation_dir, 'Psoriasis pictures Lichen Planus and related diseases')
os.mkdir(validation_Psoriasis_pictures_Lichen_Planus_and_related_diseases_dir)

validation_Seborrheic_Keratoses_and_other_Benign_Tumors_dir = os.path.join(validation_dir, 'Seborrheic Keratoses and other Benign Tumors')
os.mkdir(validation_Seborrheic_Keratoses_and_other_Benign_Tumors_dir)
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.image import imread
import pathlib
image_folder = ['Seborrheic Keratoses and other Benign Tumors',
                'Psoriasis pictures Lichen Planus and related diseases',
                'Scabies Lyme Disease and other Infestations and Bites',
                'Hair Loss Photos Alopecia and other Hair Diseases', 'Urticaria Hives',
                'Melanoma Skin Cancer Nevi and Moles',
                'Light Diseases and Disorders of Pigmentation', 'Systemic Disease',
                'Exanthems and Drug Eruptions', 'Vascular Tumors', 'Acne and Rosacea Photos']
nimgs = {}
for i in image_folder:
    nimages = len(os.listdir('/content/skin-data/train/'+i+'/'))
    nimgs[i]=nimages
plt.figure(figsize=(70, 24))
plt.bar(range(len(nimgs)), list(nimgs.values()), align='center')
plt.xticks(range(len(nimgs)), list(nimgs.keys()))
plt.title('Distribution of different classes in Training Dataset')
plt.show()
#we can just barely see the words under the chart 
#update, you can just click to zoom in lol 

img_width=256; img_height=256
batch_size=16
TRAINING_DIR = '/content/skin-data/train/'

train_datagen = ImageDataGenerator(rescale = 1/255.0,
                                   rotation_range=30,
                                   zoom_range=0.4,
                                   horizontal_flip=True)

train_generator = train_datagen.flow_from_directory(TRAINING_DIR,
                                                    batch_size=batch_size,
                                                    class_mode='categorical',
                                                    target_size=(img_height, img_width))
x, y = train_generator.next()
first_image = x[0]
first_label = y[0]
first_image, first_label = train_generator[0]

train_generator[0]

VALIDATION_DIR = '/content/skin-data/validation/'


model = Sequential([
    Conv2D(16, (3, 3), activation='relu', input_shape=(img_height, img_width, 3)), MaxPooling2D(2, 2),
    Conv2D(32, (3, 3), activation='relu'), MaxPooling2D(2, 2),
    Conv2D(64, (3, 3), activation='relu'),
    Conv2D(64, (3, 3), activation='relu'),
    MaxPooling2D(2, 2),
    Conv2D(128, (3, 3), activation='relu'),
    Conv2D(128, (3, 3), activation='relu'),
    MaxPooling2D(2, 2),
    Conv2D(256, (3, 3), activation='relu'),
    Conv2D(256, (3, 3), activation='relu'),
    Conv2D(256, (3, 3), activation='relu'),
    MaxPooling2D(2, 2),
    Flatten(),
    Dense(512, activation='relu'),
    Dense(512, activation='relu'),
    Dense(11, activation='softmax')
])
model.summary()
model.compile(optimizer='Adam', 
              loss='categorical_crossentropy', 
              metrics =['accuracy'])
history = model.fit_generator(train_generator,
                              epochs=30,
                              verbose=1,
                              validation_data=validation_generator,
                              callbacks = [best_model]
                              )

test_images_dir = '/content/Picture_Test/' #Get a file and name it as shown
test_df = pd.read_csv('/content/skin-picture_test.csv') #Create your own csv file


test_dfToList = test_df['Image_id'].tolist()
test_ids = [str(item) for item in test_dfToList]

test_images = [test_images_dir+item for item in test_ids]
test_preprocessed_images = np.vstack([preprocess_image(fn) for fn in test_images])
np.save('/content/test_preproc_CNN.npy', test_preprocessed_images)
array = model.predict(test_preprocessed_images, batch_size=1, verbose=1)
answer = np.argmax(array, axis=1)
print(answer)

I get:

TypeError Traceback (most recent call last) in ----> 1 array = model.predict(test_preprocessed_images, batch_size=1, verbose=1) 2 answer = np.argmax(array, axis=1) 3 print(answer)

            1 frames
            /usr/local/lib/python3.8/dist-packages/tensorflow/python/autograph/impl/api.py

in converted_call(f, args, kwargs, caller_fn_scope, options) 437 try: 438 if kwargs is not None: --> 439 result = converted_f(*effective_args, **kwargs) 440 else: 441 result = converted_f(*effective_args)

            TypeError: in user code:
            
            
                TypeError: tf__test_function() missing 1 required positional argument: 'steps_per_execution'

I'm wondering if there is somewhere I'm not looking. I'm pretty nooby but I wasn't expecting this error in the slightest.

I think something may be wrong with my model or something since it's "missing 1 required positional argument: 'steps_per_execution' ". Trying to get it to run but it looks like it's not my day.

  • Have you found any solution to this? I'm currently also running into this issue and I can't find any more info on it other than your question here. – April Summers Feb 03 '23 at 18:01
  • To add on to my previous comment, I think something simply loaded wrongly, I downloaded my notebook from Google Colab, then reuploaded it separately again, and it works now, seems to have been some one-time internal error. – April Summers Feb 03 '23 at 18:21
  • 1
    I managed to fix the error by removing unnecessary Tensorflow imports – Kenean Nooks Feb 04 '23 at 19:02

1 Answers1

0

Thanks @Kenean Nooks for the confirmation and mentioning your comment in the answer section for the community benefit.

This TypeError got resolved by removing unnecessary Tensorflow imports.