Skip to content
Snippets Groups Projects
Commit 0466d6f8 authored by nz11's avatar nz11
Browse files

Update resnet50_imagenet.py

parent e674f85d
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ data_format = 'channels_first'
IMAGENET_DIR = '/home/nz11/ILSVRC2012/'
OUTPUT_DIR = 'data/resnet50_imagenet_tune/'
OUTPUT_DIR = 'data/resnet50_imagenet_tune_regenerate/'
WEIGHTS_PATH = 'data/resnet50_imagenet/weights.h5'
NUM_CLASSES = 200
......@@ -217,6 +217,9 @@ y_true = np.array(y_true)
X_tune = np.array(X_tune)
y_tune = np.array(y_tune)
print ('tune size', len(X_tune))
print ('test size', len(X_test))
......@@ -267,19 +270,20 @@ model.compile(optimizer=keras.optimizers.Adam(lr=0.00001), loss='categorical_cro
if os.path.exists(WEIGHTS_PATH):
model.load_weights(WEIGHTS_PATH)
else:
model.fit_generator(generate(), steps_per_epoch=1000, validation_data=(X_test, to_categorical(y_true, num_classes=1000)), epochs=6)
model.save_weights(OUTPUT_DIR + 'weights.h5')
pass
# model.fit_generator(generate(), steps_per_epoch=1000, validation_data=(X_test, to_categorical(y_true, num_classes=1000)), epochs=6)
# model.save_weights(OUTPUT_DIR + 'weights.h5')
translate_to_approxhpvm(model, OUTPUT_DIR, X_tune, y_tune, 1000)
translate_to_approxhpvm(model, OUTPUT_DIR, X_tune, y_tune, 1000, dump_weights=False)
# dumpCalibrationData2(OUTPUT_DIR + 'test_input_10K.bin', X_test, OUTPUT_DIR + 'test_labels_10K.bin', y_true)
dumpCalibrationData2(OUTPUT_DIR + 'tune_input.bin', X_tune, OUTPUT_DIR + 'tune_labels.bin', y_tune)
dumpCalibrationData2(OUTPUT_DIR + 'test_input.bin', X_test, OUTPUT_DIR + 'test_labels.bin', y_true)
# # dumpCalibrationData2(OUTPUT_DIR + 'test_input_10K.bin', X_test, OUTPUT_DIR + 'test_labels_10K.bin', y_true)
# dumpCalibrationData2(OUTPUT_DIR + 'tune_input.bin', X_tune, OUTPUT_DIR + 'tune_labels.bin', y_tune)
# dumpCalibrationData2(OUTPUT_DIR + 'test_input.bin', X_test, OUTPUT_DIR + 'test_labels.bin', y_true)
pred = np.argmax(model.predict(X_test), axis=1)
print ('val accuracy', np.sum(pred == y_true.ravel()) / len(X_test))
pred = np.argmax(model.predict(X_tune), axis=1)
print ('val accuracy', np.sum(pred == y_tune.ravel()) / len(X_tune))
# pred = np.argmax(model.predict(X_tune), axis=1)
# print ('val accuracy', np.sum(pred == y_tune.ravel()) / len(X_tune))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment