tra_i=0
	tes_i=0
	datas = os.listdir('./data')
	print(datas)
	for e in datas:
		img = cv2.imread('./data/'+e)
		if e[0] == 'p':
			img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
			x_train[tra_i] = img
			y_train.append([0])
			tra_i+=1
		if e[0] == 'a':
			img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
			x_train[tra_i] = img
			y_train.append([1])
			tra_i+=1
	return (x_train,np.array(y_train)) , (x_test,np.array(y_test))

(x_train, y_train), (x_test, y_test) = load()
print(x_train.shape)
print(y_train.shape)
y_train = keras.utils.to_categorical(y_train, num_classes)
x_train /= 255
print(x_train.shape)
print(y_train.shape)
img_input = keras.layers.Input(shape=(224, 224, 3))
model = MobileNet(input_tensor=img_input, classes=num_classes)
model.summary()
model.compile(loss='categorical_crossentropy',optimizer = keras.optimizers.rmsprop(lr=0.0004, decay=5e-4),metrics=['accuracy'])
model.fit(x_train, y_train, validation_split =0.2,batch_size = batch_size, epochs = epochs, verbose = 1,shuffle=True)
Beispiel #2
0
        convFiles[num] = (str(convFiles[num]) + f'.{extension}')

    return convFiles


# Sorts images and labels into arrays
imgfiles = imgsort(os.listdir(args.img_dir), extension='png')

with open(args.label_dir, 'r') as f:
    labels = f.read().split(',')
    labels[len(labels) - 1] = labels[len(labels) - 1][:-1]
    labels = np.expand_dims(np.array(labels), axis=1)

print(imgfiles)
print(labels)
print(labels.shape)

print("Parsing image files...")
imgs = np.array([cv2.imread(f'{args.img_dir}{img}')
                 for img in imgfiles]) / 255.0
print(imgs.shape)

print("Loading Model...")
model = MobileNet(classes=16)
model.compile(optimizer='adam', loss='categorical_crossentropy')
model.fit(imgs, labels, epochs=EPOCHS, batch_size=BATCH_SIZE)

outputs = model.predict(imgs[:3])

print(f"outputs:\n{[letters(i) for i in outputs]}")