From abdul.sw84 at gmail.com Mon Jan 7 22:08:00 2019 From: abdul.sw84 at gmail.com (Abdul Abdul) Date: Mon, 7 Jan 2019 23:08:00 -0400 Subject: [code-quality] Keras question Message-ID: Hello, Happy new year! I wish you a happy, productive, and fruitful new year. I just have a Keras question and through you might have an idea on it, especially that I have been trying to solve the issue for a while now but couldn't yet solve the issue. The following code always predicts the same class. I tried balancing the training dataset and used different data (i.e. melanoma vs. nevus, cats vs. dogs), but always having only "1" class predicted. from keras import layers > from keras import models > from keras import optimizers > from keras.preprocessing.image import ImageDataGenerator > from sklearn.metrics import roc_curve > from sklearn.metrics import auc > import cv2 > import numpy as np > import os > > train_directory = '/train' > validation_directory = '/valid' > test_directory = '/test' > results_directory = '/results' > correct_classification = 0 > number_of_test_images = 0 > labels = [] > prediction_probabilities = [] > > model = models.Sequential() > > > model.add(layers.Conv2D(32,(3,3),activation='relu',input_shape=(512,512,3))) > model.add(layers.MaxPooling2D(2,2)) > model.add(layers.Conv2D(64,(3,3),activation='relu')) > model.add(layers.MaxPooling2D(2,2)) > model.add(layers.Conv2D(128,(3,3),activation='relu')) > model.add(layers.MaxPooling2D(2,2)) > model.add(layers.Conv2D(256,(3,3),activation='relu')) > model.add(layers.MaxPooling2D(2,2)) > model.add(layers.Conv2D(512,(3,3),activation='relu')) > model.add(layers.MaxPooling2D(2,2)) > > model.add(layers.Flatten()) > model.add(layers.Dense(1024,activation='relu')) > model.add(layers.Dense(1,activation='sigmoid')) > > > model.compile(loss='binary_crossentropy',optimizer='rmsprop',metrics=['acc']) > > train_data = ImageDataGenerator(rescale=1.0/255) > validation_data = ImageDataGenerator(rescale=1.0/255) > > train_generator = > train_data.flow_from_directory(train_directory,target_size=(512,512),batch_size=20,class_mode='binary') > validation_generator = > validation_data.flow_from_directory(validation_directory,target_size=(512,512),batch_size=20,class_mode='binary') > > history = model.fit_generator(train_generator, > steps_per_epoch=10, > epochs=10, > validation_data=validation_generator, > validation_steps=5) > > model.save('my_model.h5') > > for root, dirs, files in os.walk(test_directory): > for file in files: > img = cv2.imread(root + '/' + file) > img = cv2.resize(img,(512,512),interpolation=cv2.INTER_AREA) > img = np.expand_dims(img, axis=0) > img = img/255.0 > if os.path.basename(root) == 'nevus': > label = 1 > elif os.path.basename(root) == 'melanoma': > label = 0 > labels.append(label) > img_class = model.predict_classes(img) > img_class_probability = model.predict(img) > prediction_probability = img_class_probability[0] > prediction_probabilities.append(prediction_probability) > prediction = img_class[0] > if prediction == label: > correct_classification = correct_classification + 1 Any ideas on how the issue could be solved? Thanks a lot, and appreciate you kind support. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+python at pearwood.info Tue Jan 8 08:36:51 2019 From: steve+python at pearwood.info (Steven D'Aprano) Date: Wed, 9 Jan 2019 00:36:51 +1100 Subject: [code-quality] Keras question In-Reply-To: References: Message-ID: <20190108133647.GD10079@ando.pearwood.info> On Mon, Jan 07, 2019 at 11:08:00PM -0400, Abdul Abdul wrote: > I just have a Keras question and through you might have an idea on it, > especially that I have been trying to solve the issue for a while now but > couldn't yet solve the issue. I don't think this is relevant to this mailing list. This is for the development of linters and other code-quality tools for Python, not for general Python questions, especially not if they relate to specialist third-party libraries like Keras. See the description on the signup page: https://mail.python.org/mailman/listinfo/code-quality Try here instead: https://keras.io/#support -- Steve From iranna.gani28 at gmail.com Wed Jan 23 12:14:26 2019 From: iranna.gani28 at gmail.com (Iranna Mathapati) Date: Wed, 23 Jan 2019 22:44:26 +0530 Subject: [code-quality] How to fix::Unable to import error in Pylint Message-ID: Hi Team I have got below error when checking code style/quality using Pylint command and i have got below error. *dir1--* *-dir2*-- -PQR.py - XYZ.py -*dir3*-- -test.py $ *cd /dir1/dir2/dir3/* $ *pylint test.py * <<< in test.py have importing PQR.py and XYZ.py and its resides in dir2 *E: 1, 0: Unable to import ''PQR" (import-error)* W: 1, 0: Wildcard import PQR (wildcard-import) *E: 2, 0: Unable to import 'XYZ_variables' (import-error)* W: 2, 0: Wildcard import XYZ(wildcard-import) NOTE : if we run like *pylint dir1/dir2/dir3 *its working fine. *Pylint version::* pylint 1.8.3, astroid 1.6.0 Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0] can you please let me know how to fix it? Thanks, Iranna M -------------- next part -------------- An HTML attachment was scrubbed... URL: