text_plain_output_1.png
from glob import glob

from keras.layers import Dense

from keras.models import Sequential

from keras.wrappers.scikit_learn import KerasClassifier

from sklearn.model_selection import cross_val_score

import cv2

import numpy as np

train_data1 = glob('../input/fruits-360_dataset/fruits-360/Training/Raspberry/*')
train_data2 = glob('../input/fruits-360_dataset/fruits-360/Training/Pomelo Sweetie/*')
test_data1 = glob('../input/fruits-360_dataset/fruits-360/Test/Raspberry/*')
test_data2 = glob('../input/fruits-360_dataset/fruits-360/Test/Pomelo Sweetie/*')
x_train = []
x_test = []
def create_data(data, values):
    for i in values:
        im = cv2.imread(i, 0)
        data.append(im)
    return len(values)
train_Rasberry_size = create_data(x_train, train_data1)
train_Pomelo_size = create_data(x_train, train_data2)
test_Rasberry_size = create_data(x_test, test_data1)
test_Pomelo_size = create_data(x_test, test_data2)

x_train = np.asarray(x_train, dtype=np.float64)
x_train = x_train.reshape(x_train.shape[0], x_train.shape[1] * x_train.shape[2])
z = np.zeros(train_Rasberry_size)
o = np.ones(train_Pomelo_size)
y_train = np.concatenate((z, o), axis=0)

def build_classifier():
    classifier = Sequential()
    classifier.add(Dense(units=16, kernel_initializer='uniform', activation='relu', input_dim=x_train.shape[1]))
    classifier.add(Dense(units=8, kernel_initializer='uniform', activation='relu'))
    classifier.add(Dense(units=8, kernel_initializer='uniform', activation='relu'))
    classifier.add(Dense(units=1, kernel_initializer='uniform', activation='sigmoid'))
    classifier.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
    return classifier
model = KerasClassifier(build_fn=build_classifier, epochs=5, verbose=2)
results = cross_val_score(estimator=model, X=x_train, y=y_train, cv=3)
print('Accuracy mean:', results.mean())
print('Accuracy variance:', results.std())