{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\n#brett ALbrecht-Diego Velazquez\n\n\n# CHECK THIS OUT! https://www.python-course.eu/python_image_processing.php\n# https://medium.com/neuralspace/kaggle-1-winning-approach-for-image-classification-challenge-9c1188157a86\n\nfrom keras.models import Sequential\nfrom keras.layers.convolutional import Conv2D\nfrom keras.layers.convolutional import MaxPooling2D\nfrom keras.layers.core import Activation\nfrom keras.layers.core import Flatten\nfrom keras.layers.core import Dense\nfrom keras import backend as K\nimport sklearn\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n# import the necessary packages\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.optimizers import Adam\nfrom sklearn.model_selection import train_test_split\nfrom keras.preprocessing.image import img_to_array\nfrom keras.utils import to_categorical\n#import pyimagesearch\n#from pyimagesearch.lenet import LeNet\n#from imutils import paths\nimport matplotlib.pyplot as plt\nimport argparse\nimport random\nimport cv2\nimport os\n# the following line is only necessary in Python notebook:\n%matplotlib inline\nfrom scipy import misc\n\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nartists = []\nIMG_SIZE = 80\nDATA_DIR = \"..\"\nCATEGORIES = [\"Impressionism\", \"Surrealism\"]\n\nfor dirname, _, filenames in os.walk('/kaggle/input/best-artworks-of-all-time/images/images/'):\n    if dirname is not \"/kaggle/input/best-artworks-of-all-time/images/images/\":\n        artists.append(dirname)\n    #for filename in filenames:\n        #print(os.path.join(dirname, filename))\n\n        \ntraining_set = []\nfor a in artists:\n    \n    #SOLE impressionists for the most part. no genre crossovers yet\n    #we can still reorganize the file structure as a goal, just doing this to get data in to work with quickly.\n    if (a == '/kaggle/input/best-artworks-of-all-time/images/images/Edgar_Degas') or (a == '/kaggle/input/best-artworks-of-all-time/images/images/Claude_Monet') or (a == '/kaggle/input/best-artworks-of-all-time/images/images/Alfred_Sisley')or (a == '/kaggle/input/best-artworks-of-all-time/images/images/Camille_Pissarro') or (a == '/kaggle/input/best-artworks-of-all-time/images/images/Paul_Gauguin') or (a == '/kaggle/input/best-artworks-of-all-time/images/images/Pierre-Auguste_Renoir'):\n        print(a)\n        for img in os.listdir(a):\n            #print(img) \n            \n            img_array = cv2.imread(os.path.join(a, img))\n            #img_array = cv2.imread(os.path.joing(a, img), cv2.IMREAD_GRAYSCALE)\n            new_mat = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))\n                \n            training_set.append([new_mat, 0, os.path.join(a, img)]) #arbitrarily 0 for impressionism\n    elif (a == '/kaggle/input/best-artworks-of-all-time/images/images/Frida_Kahlo') or (a == '/kaggle/input/best-artworks-of-all-time/images/images/Marc_Chagall') or (a == '/kaggle/input/best-artworks-of-all-time/images/images/Pablo_Picasso') or (a == '/kaggle/input/best-artworks-of-all-time/images/images/Paul_Klee') or (a == '/kaggle/input/best-artworks-of-all-time/images/images/Salvador_Dali'):\n        print(a)\n        for img in os.listdir(a):\n            img_array = cv2.imread(os.path.join(a, img))\n            #img_array = cv2.imread(os.path.joing(a, img), cv2.IMREAD_GRAYSCALE)\n            new_mat = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))\n                \n            training_set.append([new_mat, 1, os.path.join(a, img)]) #arbitrarily 1 for surrealism\nprint(len(training_set))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import random\nrandom.shuffle(training_set)\nfor sample, cat, pathOG in training_set[:5]:\n    plt.figure(figsize=(12,12))\n    \n    \n    plt.subplot(1,2,1)\n    plt.imshow(sample, cmap='gray')\n    \n    \n    plt.subplot(1,2,2)\n    img=cv2.imread(pathOG)\n    imgplot = plt.imshow(img)\n    \n    plt.show()\n    \n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X = []\nY = []\n\nfor features, label, path in training_set:\n    X.append(features)\n    Y.append(label)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\n# set the matplotlib backend so figures can be saved in the backgro","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"EPOCHS = 25\nINIT_LR = 1e-3\nBS = 32\n\n\n\n# scale the raw pixel intensities to the range [0, 1]\ndata = np.array(X, dtype=\"float\") / 255.0\nlabels = np.array(Y)\n\n# partition the data into training and testing splits using 75% of\n# the data for training and the remaining 25% for testing\n(trainX, testX, trainY, testY) = train_test_split(data,\n\tlabels, test_size=0.25, random_state=42)\n\n# convert the labels from integers to vectors\ntrainY = to_categorical(trainY, num_classes=2)\ntestY = to_categorical(testY, num_classes=2)\n\n# scale the raw pixel intensities to the range [0, 1]\ndata = np.array(X, dtype=\"float\") / 255.0\nlabels = np.array(Y)\n \n# partition the data into training and testing splits using 75% of\n# the data for training and the remaining 25% for testing\n(trainX, testX, trainY, testY) = train_test_split(data, labels, test_size=0.25, random_state=42)\n \n# convert the labels from integers to vectors\ntrainY = to_categorical(trainY, num_classes=2)\ntestY = to_categorical(testY, num_classes=2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"aug = ImageDataGenerator(rotation_range=30, width_shift_range=0.1,\n    height_shift_range=0.1, shear_range=0.2, zoom_range=0.2,\n    horizontal_flip=True, fill_mode=\"nearest\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"%pylab inline\n\n\nimg=imread('../input/best-artworks-of-all-time/images/images/Leonardo_da_Vinci/Leonardo_da_Vinci_78.jpg')\nimgplot = plt.imshow(img)\nplt.show()\n\n\n","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}