tensorflow / tensorflow/privacy

ValueError: Dimension size must be evenly divisible by 10 but is 1 for '{{node training/Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](loss/mul, training/Reshape/shape)' with input shapes: [], [2] and with input tensors computed as partial shapes: input[1] = [10,?]

Open
#180 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2k
Forks
477
Avg merge
22h 12m
Merged PRs (30d)
1

Description

Hello,
I am trying to train with differential privacy using tensorflow_privacy.DPKerasSGDOptimizer() here is my code

E = 1
B = 100
N = 2
dataset = pickle.load( open(path, "rb" ) )
data = deepcopy(dataset)
list_cli = list(dataset.keys())

for client in list_cli:
     data[client]['x_train'] = dataset[client]['x_train'][:int((len(dataset[client]['x_train'])//batch_length)*batch_length)]
     data[client]['y_train'] = dataset[client]['y_train'][:int((len(dataset[client]['y_train'])//batch_length)*batch_length)]
     data[client]['x_test'] = dataset[client]['x_test'][:int((len(dataset[client]['x_test'])//B)*B)]
     data[client]['y_test'] = dataset[client]['y_test'][:int((len(dataset[client]['y_test'])//B)*B)]

hparams = {'E' : E, 'B' : B, 'N' : N}

#DP parameters
l2_norm_clip = 1.5
noise_multiplier = Noise
num_microbatches = 10
learning_rate = 0.25

#DP optimizer
dpsgd = tensorflow_privacy.DPKerasSGDOptimizer(
l2_norm_clip=l2_norm_clip,
noise_multiplier=noise_multiplier,
num_microbatches=num_microbatches,
learning_rate=learning_rate)

model.compile(optimizer=dpsgd, loss='categorical_crossentropy', metrics=['accuracy'])

model.fit(data[str(client)]['x_train'], data[str(client)]['y_train'], epochs=self.hparams['E'], batch_size=hparams['B'], validation_data=(data[str(client)]['x_test'], data[str(client)]['y_test']))

I get the following error :

ValueError: Dimension size must be evenly divisible by 10 but is 1 for '{{node training/Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](loss/mul, training/Reshape/shape)' with input shapes: [], [2] and with input tensors computed as partial shapes: input[1] = [10,?]

Note the when I use

model.compile(optimizer="Adam", loss='categorical_crossentropy', metrics=['accuracy'])

The code executes without errors.

Do you have any ideas ?

Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the model.fit call and tensorflow_privacy.DPKerasSGDOptimizer configuration shown in the report, especially num_microbatches=10 and batch_size=B. Reproduce the reshape error with the reported training setup and compare it with the Adam configuration. Done means identifying the incompatible configuration or missing condition and documenting or correcting it with a focused regression check.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.