# keras Sequential CNN for image data reshaping data issues

I am new at keras and CNN and am working on building at CNN for sequential analysis of movement in a image. What I am having issues with is the reshaping the data and the labels that go into the fitting and testing the data for the model. So the original size/shape of the numpy file is (18, 50,50,16) which is saved in a text file from another program. I know the text file is ok because I can read it in and display it correctly with the debug_potion method. So that looks good. There are 18 images in the folder for the data and otherData variable. I dont really know what the 16 is but the image size are 50*50.

The issue is the reshaping of that data is the problem. Can anyone suggest how to reshape this data in a way that I can train it. I think I need to do onehot encoding but not quite sure how. Any help will be appreciated. Here is what I have so far.

def debug_potion(data):
for i in range(0, 16):
# get for each joint
potion = Potion(data)
plt.show(potion.display(joints=[i, i], channels=[0, 1, 2]))

# Build Model for sequential building
def create_model(input_shape):
model = Sequential()
activation='relu',
input_shape=input_shape))

model.compile(loss=keras.losses.categorical_crossentropy,
metrics=['accuracy'])
return model

with open(file, "rb") as f:

batch_size = 1
num_classes = 2
epochs = 12

# input image dimensions
img_rows, img_cols = 50, 50
input_shape = (img_rows, img_cols, 16)

data = np.array(data)
otherData = np.array(otherData)
print("Data shape", otherData.shape)

xtrain = []
ytrain = []
xtest  = []
ytest  = []

for x in range(0,len(data)):
if x < 15:
xtrain.append(data)
ytrain.append(("FWAC", num_classes))
else:
xtest.append(data)
ytest.append(("FWAC", num_classes))

for x in range(0,len(otherData)):
if x < 15:
xtrain.append(otherData)
ytrain.append(("Other", num_classes))
else:
xtest.append(otherData)
ytest.append(("Other", num_classes))

#Create x test and train arrays
xtrain = np.array(xtrain)
xtrain = xtrain.reshape(30,img_rows, img_cols,16)
ytrain = np.array(ytrain)

xtest = np.array(xtest)
xtest = xtest.reshape(108, img_rows, img_cols,16)
ytest = np.array(ytest)
print(xtrain.shape)
print(xtest.shape)
print(ytrain.shape)
print(ytest.shape)

# Build Model
model = create_model(input_shape)

model.fit(xtrain, ytrain,
batch_size = batch_size,
epochs = epochs,
verbose=1,
validation_data=(xtest, ytest))

score = model.evaluate(xtest,ytest, verbose=0)
print(("Test loss", score[0]))
print("Test Accuracy", score[1])

• Videos generally have 4 dimensions Oct 31, 2018 at 6:03

    xtrain = xtrain.reshape(xtrain.shape[0],img_rows,img_cols,16)