I have dataset of Arabic handwritten digits that i want to using it for classifying , this dataset is consist of two directory (Training set & Testing set) and the dimensions of each image is (28 * 28) and every directory has a subfolders , the problem that the extension of image files in (BMP) and i don't know how can i import to my code in python with keras , anyone can help me please
Asked
Active
Viewed 215 times
-1
-
Here is a thread on reading BMP files in python: https://stackoverflow.com/questions/10439104/reading-bmp-files-in-python – Austin Andrews Apr 19 '19 at 15:15
1 Answers
0
Delete all the tripple quotes, this should get you started
import numpy as np
from PIL import Image
import random
import os
import pickle
DATADIR = "" '''The Path to your dataset but dont include the folders that contain the data as OS will do this for you'''
CATEGORIES = ['''List the names of each folder containing data that you want to access''']
training_data = []
def create_training_data():
for category in CATEGORIES:
path = os.path.join(DATADIR, category)
class_num = CATEGORIES.index(category)
for img in os.listdir(path):
image = Image.open(os.path.join(path,img))
img_array = np.asarray(image, dtype = np.int64)
training_data.append([img_array, class_num])
create_training_data()
random.shuffle(training_data)
training_inputs = []
training_outputs = []
for features, label in training_data:
training_inputs.append(features)
training_outputs.append(label)
for i in range(len(training_inputs)):
training_inputs[i].reshape(50,50)
pickle_out = open('Training Outputs.pickle', 'wb')
pickle.dump(training_inputs, pickle_out)
pickle_out.close()
pickle_out = open('Training Inputs.pickle', 'wb')
pickle.dump(training_outputs, pickle_out)
pickle_out.close()

Kaleba KB Keitshokile
- 1,656
- 1
- 6
- 12
-
-
It should be training_inputs, I've fixed it now sorry. I must have missed it because I tried to use clearer variables for the explanation. The code is from a project I once worked on – Kaleba KB Keitshokile Apr 22 '19 at 17:54
-
The Pickle dumps will save your data so you don't have to recreate the data set each time. So in your other script you should just say e.g. ```training_inputs = pickle.load( open( 'Training Inputs.pickle', 'r'))``` this will just pull the saved data because when you don't want to be recreating datasets every time. – Kaleba KB Keitshokile Apr 23 '19 at 03:29
-
1