Skip to content

Update tensorflow data handler #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Files/mnist_keras_data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pickle
import numpy as np

from ibmfl.data.data_handler import DataHandler
from ibm_watson_machine_learning.federated_learning.data_handler import DataHandler

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -38,14 +38,14 @@ def get_data(self, nb_points=500):
logger.info(
'Loaded training data from ' + str(self.train_file_name))
with open(self.train_file_name, 'rb') as f:
(x_train, y_train)= pickle.load(f)
(self.x_train, self.y_train)= pickle.load(f)
logger.info(
'Loaded test data from ' + str(self.test_file_name))
with open(self.test_file_name, 'rb') as f:
(x_test, y_test)= pickle.load(f)
(self.x_test, self.y_test)= pickle.load(f)

x_train = x_train / 255.0
x_test = x_test / 255.0
self.x_train = self.x_train / 255.0
self.x_test = self.x_test / 255.0


except Exception:
Expand All @@ -55,11 +55,11 @@ def get_data(self, nb_points=500):

# Add a channels dimension
import tensorflow as tf
x_train = x_train[..., tf.newaxis]
x_test = x_test[..., tf.newaxis]
self.x_train = self.x_train[..., tf.newaxis]
self.x_test = self.x_test[..., tf.newaxis]

print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')
print('self.x_train shape:', self.x_train.shape)
print(self.x_train.shape[0], 'train samples')
print(self.x_test.shape[0], 'test samples')

return (x_train, y_train), (x_test, y_test)
return (self.x_train, self.y_train), (self.x_test, self.y_test)