什么是最适合将一个输入图像映射到两个输出的神经网络架构?

我使用EMNIST生成了一个数据集,每个图像包含一个字符或两个字符。图像尺寸为28×56(高x宽)。

我主要是想预测给定图像中的一个或两个字符。我不确定应该采用哪种架构来实现这一点。共有62个字符类别。

例如:-单个字符 两个字符

对于单个字符,y = [23]

对于两个字符,y = [35,11]

我尝试了以下方法。

  1. 我尝试通过CTC来实现,但遇到了无法解决的无限损失问题。
  2. 我用62填充单个字符的真实标签以表示空白字符,并训练了一个具有以下层的CNN。

print()

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)y_train = sequence.pad_sequences(y_train, padding='post', value = 62)y_test = sequence.pad_sequences(y_test,padding='post', value = 62)X_train = X_train/255.0X_test = X_test/255.0input_shape = (28, 56, 1)model = Sequential()model.add(Conv2D(filters=72, kernel_size=(11,11), padding = 'same', activation='relu',input_shape=input_shape))model.add(MaxPooling2D(pool_size=(2,2),strides=2))model.add(Conv2D(filters=144, kernel_size=(7,7) , padding = 'same', activation='relu'))model.add(Conv2D(filters=144, kernel_size=(3,3) , padding = 'same', activation='relu'))model.add(MaxPooling2D(pool_size=(2,2)))model.add(Flatten())model.add(Dense(units=1024, activation='relu'))model.add(Dropout(.5))model.add(Dense(512, activation='relu'))model.add(Dense(units=2, activation='relu'))model.compile(loss='mse', optimizer='adam', metrics=['accuracy'])model.summary()batch_size = 128steps = math.ceil(X_train.shape[0]/batch_size)datagen = ImageDataGenerator(        featurewise_center=False,  # set input mean to 0 over the dataset        samplewise_center=False,  # set each sample mean to 0        featurewise_std_normalization=False,  # divide inputs by std of the dataset        samplewise_std_normalization=False,  # divide each input by its std        zca_whitening=False,  # apply ZCA whitening        rotation_range=0,  # randomly rotate images in the range (degrees, 0 to 180)        zoom_range = 0.2, # Randomly zoom image        width_shift_range=0.2,  # randomly shift images horizontally (fraction of total width)        height_shift_range=0.1,  # randomly shift images vertically (fraction of total height)        horizontal_flip=False,  # randomly flip images        vertical_flip=False)history = model.fit_generator(datagen.flow(X_train,y_train, batch_size=batch_size),                              epochs = 6, validation_data = (X_test, y_test),                              verbose = 1,steps_per_epoch=steps)

我能够在验证集上达到大约90%的准确率。然而,当我输入生成的图像来查看其预测结果时,预测结果与正确分类相差几个字符。我在创建模型或预处理数据的方式上是否有问题?


回答:

我已经认识到我的错误。我试图使用回归方法来解决这个问题,而实际上这是一个分类问题。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注