Ejemplo n.º 1
0
from tensorflow.python.keras.utils import plot_model
plot_model(model, to_file='keras-logos-gen-model.png', show_shapes=True, show_layer_names=True)

model.summary()

model.fit_generator(train_dir_iterator, epochs=20)

#print(model.evaluate_generator(test_dir_iterator, verbose=1))

with open("keras-logos-gen-predictions.txt", 'w') as out:
    idx = 0
    for batch in test_dir_iterator:
        filenames = test_dir_iterator.filenames[idx : idx + test_dir_iterator.batch_size]
        if len(filenames) == 0:
            break
        idx += test_dir_iterator.batch_size
        predictions = model.predict_on_batch(batch[0])
        for i in range(len(predictions)):
            truth = test_class_map[np.argmax(batch[1][i])]
            conf = np.max(predictions[i])
            if conf > 0.25:
                predicted = train_class_map[np.argmax(predictions[i])]
            else:
                predicted = "no-logo"
            m = re.match(r".*/(\d+)\.jpg", filenames[i])
            fid = m.group(1)
            print("file = %s\ttruth = %s\tpredicted = %s\tconfidence = %f" % (filenames[i], truth, predicted, conf))
            out.write("%s, %s, %f\n" % (fid, predicted, conf))

Ejemplo n.º 2
0
plt.plot(history.history['val_mean_absolute_error'],
         label='MSE (validation data)')
plt.title('MAE for celab2000')
plt.ylabel('MAE value')
plt.xlabel('No. epoch')
plt.legend(loc="upper left")
plt.show()

#predictions

#getting the input as list
inputs = genfromtxt('cielab2000_sample_input-15000.csv', delimiter=',')

start1 = time.time()  #pin starting point
#model prediction
prediction = model.predict_on_batch(np.array(inputs))
end1 = time.time()  #pin ending point
print(prediction)
print(end1 - start1)
# print(end1-start1)
# print(results1)

results2 = list()
#color math delta calculation
start2 = time.time()  #pin starting point
for j in range(0, len(inputs)):
    l1, a1, b1, l2, a2, b2 = np.array(inputs[j])
    output = getdelta_e_cie2000(l1, a1, b1, l2, a2, b2)
    rounded_output = np.round(output, 5)
    results2.append(rounded_output)
norm = [float(k) / max(results2) for k in results2]