Skip to content

Cocktail branch inconsistencies #275

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 7 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions autoPyTorch/pipeline/components/setup/network/base_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ def _predict(self, network: torch.nn.Module, loader: torch.utils.data.DataLoader
# Batch prediction
Y_batch_preds = list()

for i, (X_batch, Y_batch) in enumerate(loader):
# Predict on batch
X_batch = X_batch.float().to(self.device)
Y_batch_pred = network(X_batch)
if self.final_activation is not None:
Y_batch_pred = self.final_activation(Y_batch_pred)
Y_batch_preds.append(Y_batch_pred.detach().cpu())
with torch.no_grad():
for i, (X_batch, Y_batch) in enumerate(loader):
# Predict on batch
X_batch = X_batch.float().to(self.device)
Y_batch_pred = network(X_batch)
if self.final_activation is not None:
Y_batch_pred = self.final_activation(Y_batch_pred)
Y_batch_preds.append(Y_batch_pred.detach().cpu())

return torch.cat(Y_batch_preds, 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def backward(ctx: typing.Any,

def shake_get_alpha_beta(is_training: bool, is_cuda: bool
) -> typing.Tuple[torch.tensor, torch.tensor]:
if is_training:
if not is_training:
result = (torch.FloatTensor([0.5]), torch.FloatTensor([0.5]))
return result if not is_cuda else (result[0].cuda(), result[1].cuda())

Expand All @@ -118,10 +118,10 @@ def shake_drop_get_bl(
) -> torch.tensor:
pl = 1 - ((block_index + 1) / num_blocks) * (1 - min_prob_no_shake)

if not is_training:
if is_training:
# Move to torch.randn(1) for reproducibility
bl = torch.tensor(1.0) if torch.randn(1) <= pl else torch.tensor(0.0)
if is_training:
else:
bl = torch.tensor(pl)

if is_cuda:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def get_loader(self, X: np.ndarray, y: Optional[np.ndarray] = None, batch_size:
dataset = BaseDataset(
train_tensors=(X, y),
# This dataset is used for loading test data in a batched format
seed=self.random_state.get_state()[1][0],
shuffle=False,
train_transforms=self.test_transform,
val_transforms=self.test_transform,
)
Expand Down
11 changes: 3 additions & 8 deletions autoPyTorch/pipeline/tabular_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ def _predict_proba(self, X: np.ndarray) -> np.ndarray:
loader = self.named_steps['data_loader'].get_loader(X=X)
pred = self.named_steps['network'].predict(loader)
if isinstance(self.dataset_properties['output_shape'], int):
proba = pred[:, :self.dataset_properties['output_shape']]
normalizer = proba.sum(axis=1)[:, np.newaxis]
normalizer[normalizer == 0.0] = 1.0
proba /= normalizer

return proba
return pred

else:
all_proba = []
Expand Down Expand Up @@ -147,8 +142,8 @@ def predict_proba(self, X: np.ndarray, batch_size: Optional[int] = None) -> np.n

# Neural networks might not be fit to produce a [0-1] output
# For instance, after small number of epochs.
y = np.clip(y, 0, 1)
y = sklearn.preprocessing.normalize(y, axis=1, norm='l1')
# y = np.clip(y, 0, 1)
# y = sklearn.preprocessing.normalize(y, axis=1, norm='l1')

return y

Expand Down