def test_temporal_sample_weights(self):
    num_classes = 5
    weighted_class = 3
    train_samples = 1000
    test_samples = 1000
    input_dim = 5
    timesteps = 3
    model = keras.models.Sequential()
    model.add(keras.layers.TimeDistributed(keras.layers.Dense(num_classes), input_shape=(timesteps, input_dim)))
    model.add(keras.layers.Activation('softmax'))
    np.random.seed(1337)
    ((_, y_train), _) = testing_utils.get_test_data(train_samples=train_samples, test_samples=test_samples, input_shape=(input_dim,), num_classes=num_classes)
    int_y_train = y_train.copy()
    y_train = keras.utils.to_categorical(y_train, num_classes)
    class_weight = dict([(i, 1.0) for i in range(num_classes)])
    class_weight[weighted_class] = 2.0
    sample_weight = np.ones(y_train.shape[0])
    sample_weight[(int_y_train == weighted_class)] = 2.0
    with self.assertRaises(ValueError):
        model.compile(loss='binary_crossentropy', optimizer=RMSPropOptimizer(learning_rate=0.001), sample_weight_mode='temporal')
def test_temporal_sample_weights(self):
    num_classes = 5
    weighted_class = 3
    train_samples = 1000
    test_samples = 1000
    input_dim = 5
    timesteps = 3
    model = keras.models.Sequential()
    model.add(keras.layers.TimeDistributed(keras.layers.Dense(num_classes), input_shape=(timesteps, input_dim)))
    model.add(keras.layers.Activation('softmax'))
    np.random.seed(1337)
    ((_, y_train), _) = testing_utils.get_test_data(train_samples=train_samples, test_samples=test_samples, input_shape=(input_dim,), num_classes=num_classes)
    int_y_train = y_train.copy()
    y_train = keras.utils.to_categorical(y_train, num_classes)
    class_weight = dict([(i, 1.0) for i in range(num_classes)])
    class_weight[weighted_class] = 2.0
    sample_weight = np.ones(y_train.shape[0])
    sample_weight[(int_y_train == weighted_class)] = 2.0
    with self.assertRaises(ValueError):
        model.compile(loss='binary_crossentropy', optimizer=RMSPropOptimizer(learning_rate=0.001), sample_weight_mode='temporal')