# Wandb is doing the same possibility multiple times

**URL:** <https://community.wandb.ai/t/wandb-is-doing-the-same-possibility-multiple-times/1667>\
**Category:** W&B Help\
**Tags:** sweeps\
**Created:** [January 2, 2022, 9:38pm UTC](https://community.wandb.ai/t/wandb-is-doing-the-same-possibility-multiple-times/1667 "2022-01-02T21:38:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yasarniyaz](https://avatars.discourse-cdn.com/v4/letter/y/53a042/32.png) [@yasarniyaz](https://community.wandb.ai/u/yasarniyaz)\
**Post date:** [January 2, 2022, 9:38pm UTC](https://community.wandb.ai/t/wandb-is-doing-the-same-possibility-multiple-times/1667/1 "2022-01-02T21:38:15Z")

</div>

hi, i am working on private data with keras. I use different activation functions and optimization algorithms. I’m doing this wandb sweep, but it trains one possibility more than once. example relu-lr=0.001-adam-batch\_size=4 has trained probability more than 6 times. what is the reason of this. and I’m not sure of the correctness of my code

my code :

```auto
import tensorflow as tf
import numpy as np
base_dir="/content/f1"

train_datagen=tf.keras.preprocessing.image.ImageDataGenerator(
    rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True,
    validation_split=0.1
    )

test_datagen=tf.keras.preprocessing.image.ImageDataGenerator(
     rescale=1./255,
     validation_split=0.1
)

train_datagen=train_datagen.flow_from_directory(
    base_dir,
    target_size=(500,500),
    subset='training',
    batch_size=2
)

test_datagen=test_datagen.flow_from_directory(
    base_dir,
    target_size=(500,500),
    subset='validation',
    batch_size=2
)
wandb.login()
sweep_config = {
    'method': 'random',
    'metric': {
      'name': 'accuracy',
      'goal': 'maximize'   
    },
    'parameters': {
        'epochs': {
            'values': [2,4]
        },
        'learning_rate': {
            'values': [0.01,0.001]
        },
        'optimizer': {
            'values': ['adam','rmsprop']
        },
        'activation': {
            'values': ['relu', 'elu', 'selu']
        }
    }
}
sweep_id = wandb.sweep(sweep_config, entity="sdad", project="func")
def train():
    config_defaults = {
        'epochs': 2,
        'batch_size': 2,
        'learning_rate': 0.001,
        'activation': 'relu',
        'optimizer': 'adam',
        'seed': 42
    }

    wandb.init(config=config_defaults)
    
    config = wandb.config
    
    model= Sequential()

    model.add(layers.Conv2D(filters=4,activation=config.activation,kernel_size=(5,5),input_shape=(500,500,3)))
    model.add(layers.MaxPooling2D((2,2)))
    model.add(layers.Conv2D(filters=8,activation=config.activation,kernel_size=(3,3)))
    model.add(layers.MaxPooling2D((2,2)))
    model.add(layers.Conv2D(filters=16,activation=config.activation,kernel_size=(2,2)))
    model.add(layers.MaxPooling2D((2,2)))
    model.add(layers.Conv2D(filters=32,activation=config.activation,kernel_size=(2,2)))

    model.add(layers.Flatten())

    model.add(Dense(50,activation=config.activation))
    model.add(Dense(100,activation=config.activation))
    model.add(Dense(100,activation=config.activation))
    model.add(Dense(50,activation=config.activation))
    model.add(Dense(4,activation="softmax"))

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

    model.fit(train_datagen, batch_size=config.batch_size,
              epochs=config.epochs,
              validation_data=test_datagen,
              callbacks=[WandbCallback(data_type="image", validation_data=test_datagen)])

```

 ![sweplıntısı](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/9dbbeab2a807227267a91e6519a401beaaa15592.jpeg)

---

<div class="post-metadata">

**Author:** ![armanharutyunyan](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@armanharutyunyan](https://community.wandb.ai/u/armanharutyunyan)\
**Post date:** [January 3, 2022, 4:27am UTC](https://community.wandb.ai/t/wandb-is-doing-the-same-possibility-multiple-times/1667/2 "2022-01-03T04:27:32Z")

</div>

Hey Yasar, I believe the issue is that you are using random search with a list of constant parameters. Random search will retry parameter combinations after a while. You can pass a [count argument to the wandb agent](https://docs.wandb.ai/guides/sweeps/faq#why-are-my-sweep-agents-running-forever-is-there-a-way-to-set-a-maximum-number-of-runs) call to specify the number of experiments to run to avoid this.

---

<div class="post-metadata">

**Author:** ![yasarniyaz](https://avatars.discourse-cdn.com/v4/letter/y/53a042/32.png) [@yasarniyaz](https://community.wandb.ai/u/yasarniyaz)\
**Post date:** [January 3, 2022, 9:36am UTC](https://community.wandb.ai/t/wandb-is-doing-the-same-possibility-multiple-times/1667/3 "2022-01-03T09:36:37Z")

</div>

Thank you my friend, the problem has been solved thanks to you. I am thankful to you

---

<div class="post-metadata">

**Author:** ![armanharutyunyan](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@armanharutyunyan](https://community.wandb.ai/u/armanharutyunyan)\
**Post date:** [January 4, 2022, 5:16am UTC](https://community.wandb.ai/t/wandb-is-doing-the-same-possibility-multiple-times/1667/4 "2022-01-04T05:16:37Z")

</div>

Glad to hear it, Yasar

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [March 5, 2022, 5:16am UTC](https://community.wandb.ai/t/wandb-is-doing-the-same-possibility-multiple-times/1667/5 "2022-03-05T05:16:57Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
