Target Y-label ValueError: assignment destination is read-only

问题描述 投票:0回答:0
from keras.datasets import fashion_mnist
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()

# Split the original training data into a validation set
x_train, x_val, y_train, y_val = train_test_split(x_train, y_train, test_size=0.2, random_state=42)

def poison(x_train_sample): 
  sample = cv2.add(x_train_sample,imgSm)
  return (sample.reshape(28,28))

x_train = x_train.astype("float32") 
x_test = x_test.astype("float32")
x_val = x_val.astype("float32")

#poison 600 samples, eventually 50 poison samples is sufficient to successfully perform the trojan attack.

for i in range(600): 
    x_train[i]=poison(x_train[i])
    y_train[i]=7 #target class is 7

for i in range(x_test.shape[0]):
  x_test[i]=poison(x_test[i])
  y_test[i]=7 #target class is 7

----> 3 y_test[i]=7 #target class is 7

ValueError:赋值目标是只读的

我正在进行中毒攻击,其中还包括标签翻转,所以

poison function
正在执行将两个图像添加或合并为一个图像,并且标签在此处更改为特定目标 7 但卡在这个错误中。

keras deep-learning mnist ml poison
© www.soinside.com 2019 - 2024. All rights reserved.