def representative_dataset_generator(): train_data, train_filenames, train_labels, test_data, test_filenames, test_labels, label_names = \ train.load_cifar_10_data(cifar_10_dir) _idx = np.load('calibration_samples_idxs.npy') for i in _idx: sample_img = np.expand_dims(np.array(test_data[i], dtype=np.float32), axis=0) yield [sample_img]
def representative_dataset_generator(): train_data, train_filenames, train_labels, test_data, test_filenames, test_labels, label_names = \ train.load_cifar_10_data(cifar_10_dir) _idx = np.array(range(10000)) np.random.shuffle(_idx) for i in _idx[:500]: print(i) sample_img = np.expand_dims(np.array(test_data[i], dtype=np.float32), axis=0) yield [sample_img]
_name = keras_model.get_quant_model_name() model_path = 'trained_models/' + _name + '.tflite' if __name__ == '__main__': # Load the TFLite model and allocate tensors. interpreter = tf.lite.Interpreter(model_path=model_path) interpreter.allocate_tensors() # Get input and output tensors. input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() cifar_10_dir = 'cifar-10-batches-py' train_data, train_filenames, train_labels, test_data, test_filenames, test_labels, label_names = \ train.load_cifar_10_data(cifar_10_dir) label_classes = np.argmax(test_labels, axis=1) print("Label classes: ", label_classes.shape) x = [] y = [] for i in range(len(test_data)): x.append(test_data[i]) y.append(test_labels[i]) if QUANT_MODEL: test_imgs = np.array(x, dtype=np.int64) test_imgs = test_imgs - 128 test_imgs = test_imgs.astype(np.int8)