The tensor y_true is the true data (or target, ground truth) you pass to the fit method. It's a conversion of the numpy array y_train into a tensor.
The tensor y_pred is the data predicted (calculated, output) by your model.
Both y_true and y_pred have exactly the same shape, always.
It contains an entire batch. Its first dimension is always the batch size, and it must exist, even if the batch has only one element.
Two very easy ways to find the shape of y_true are:
check your true/target data: print(Y_train.shape)
check your model.summary() and see the last output
But its first dimension will be the batch size.
So, if your last layer outputs (None, 1), the shape of y_true is (batch, 1). If the last layer outputs (None, 200,200, 3), then y_true will be (batch, 200,200,3).
Mean Squared Error (MSE) is a common loss function used for regression problems (different than classification problems).
Similarly, evaluation metrics used for regression differ from classification. A common regression metric is Mean Absolute Error (MAE).
对于分类任务:
常使用交叉损失熵作为loss
常使用accuracy作为metrics
如果使用categorical_crossentropy,需要事先转成稀疏形式表达的向量。
Note: when using the categorical_crossentropy loss, your targets should be in categorical format (e.g. if you have 10 classes, the target for each sample should be a 10-dimensional vector that is all-zeros except for a 1 at the index corresponding to the class of the sample). In order to convert integer targets into categorical targets, you can use the Keras utility to_categorical:
import tensorflow as tf
from tensorflow.python import keras as keras
STEPS_PER_EPOCH= SUM_OF_ALL_DATASAMPLES / BATCHSIZE
#Get your datatensors
image, label = create_dataset(filenames_train)
#Combine it with keras
model_input = keras.layers.Input(tensor=image)
#Build your network
model_output = keras.layers.Flatten(input_shape=(-1, 255, 255, 1))(model_input)
model_output = keras.layers.Dense(1000, activation='relu')(model_output)
#Create your model
train_model = keras.models.Model(inputs=model_input, outputs=model_output)
#Compile your model
train_model.compile(optimizer=keras.optimizers.RMSprop(lr=0.0001),
loss='mean_squared_error',
metrics=[soft_acc],
target_tensors=[label])
#Train the model
train_model.fit(epochs=EPOCHS,
steps_per_epoch=STEPS_PER_EPOC)
#More Kerasstuff here
if shuffle==True:
shuffle(x,y)#打乱
while(True):
for i in range(0,len(x),batch_size):
x_batch=x[i:i+batch_size]
y_batch=y[i:i+batch_size]
ImagePro(x_batch)#数据增强
saveToFile()#保存提升后的图片
yield (x_batch,y_batch)
path = '/home/ubuntu/dataset/dogs_cats_sample/'
gen_path = '/home/ubuntu/dataset/dogs_cats_gen/'
datagen = image.ImageDataGenerator()
gen_data = datagen.flow_from_directory(path, batch_size=1, shuffle=False,
save_to_dir=gen_path+'18',
save_prefix='gen', target_size=(224, 224))
for i in range(9):
gen_data.next() #此处并不使用其返回值(x,y)元祖,只是将其保存图片。
fig = print_result(gen_path+'18/*')