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() model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape)) model.add(Conv2D(64, (3, 3), activation='relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(128, activation='relu')) model.add(Dropout(0.5)) model.add(Dense(num_classes, activation='softmax')) model.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.Adadelta(), metrics=['accuracy']) return model def read_in_data(file): with open(file, "rb") as f: return pickle.load(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 = read_in_data("heatmap.txt") otherData = read_in_data("othermove.txt") 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)) print("Test Accuracy", score)