Using Keras, how can I enter X_train images (over a thousand images)?

My application is automotive accident prevention systems using machine learning (convolutional neural networks). My images are 200x100 JPG images, and the output is an array of 4 elements: the car will move left, right, stop or move forward. Thus, the output will have one element 1(in accordance with the correct action to be taken), and 3 other elements will be 0.

I want to train my car now to help her insert any image and decide the action on her own. Here is my code:

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D
from keras.optimizers import SGD

import numpy as np

model = Sequential()

model.add(Convolution2D(16, 1, 1, border_mode='valid', dim_ordering='tf', input_shape=(200, 150, 1)))
model.add(Activation('relu'))
model.add(Convolution2D(16, 1, 1))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25)) #Cannot take float values

model.add(Convolution2D(32, 1, 1, border_mode='valid'))
model.add(Activation('relu'))
model.add(Convolution2D(32, 1, 1))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Flatten())
# Note: Keras does automatic shape inference.
model.add(Dense(256))
model.add(Activation('relu'))
model.add(Dropout(0.5))

model.add(Dense(10))
model.add(Activation('softmax'))

model.fit(X_train, Y_train, batch_size=32, nb_epoch=1)

How can I enter my images (I have them on my PC)? And how can I point the Y-train?

+4
3

Keras, , , , ImageDataGenerator, - flow_from_directory, @isaac-moore. flow from directory , Y_train.

python, , :

(, , .) , 2 3 . , Kaggle Github.

+6

, .

  train_generator = train_datagen.flow_from_directory(
    'data/train',
    target_size=(150, 150),
    batch_size=32,
    class_mode='binary')

keras.io

+2

Source: https://habr.com/ru/post/1660071/


All Articles