Method and apparatus for generating neural network model, and computer-readable storage medium
View Patent ↗In a method causing an electronic device to generate a neural network model that controls a game element, a hyperparameter value in a first neural network model is determined from a hyperparameter value set. A structural layer of the first neural network model includes the hyperparameter value, and an output layer, an input layer, and the structural layer are connected in a target connection. A first model accuracy of a second neural network model is obtained by training the first neural network model, and hyperparameter values of some hyperparameters in the first neural network model are updated to corresponding target hyperparameter values if the first model accuracy is lower than a target accuracy.
1 . A method for an electronic device to generate a neural network model configured to control a non-player game element in a game, comprising:
determining, with processing circuitry of the electronic device, hyperparameter values for a first neural network model from a hyperparameter value set, the first neural network model comprising an input layer, a structural layer, and an output layer, the input layer connected in a target connection, the structural layer including a plurality of first structural blocks and a plurality of second structural blocks, the hyperparameter value set including a plurality of first hyperparameter value subsets and a plurality of second hyperparameter value subsets, the plurality of first structural blocks are in a one-to-one correspondence with the plurality of first hyperparameter value subsets, and the plurality of second structural blocks are in a one-to-one correspondence with the plurality of second hyperparameter value subsets, wherein
a first hyperparameter value corresponding to a first hyperparameter, for each of the plurality of first structural blocks, is determined from the corresponding first hyperparameter value subset, and
a second hyperparameter value corresponding to a second hyperparameter, for each of the plurality of second structural blocks, is determined from the corresponding second hyperparameter value subset;
obtaining a first model accuracy of a second neural network model by training the first neural network model;
in a case that the first model accuracy is lower than a target accuracy, updating, by the processing circuitry of the electronic device, hyperparameter values of some hyperparameters in the first neural network model to values from the hyperparameter value set to obtain a third neural network model;
obtaining a second model accuracy of a fourth neural network model by training the third neural network model using a verification sample set from a target application; and
determining, based on the fourth neural network model and the second model accuracy being greater than or equal to the target accuracy, operation data that indicates one or more actions to be performed by the non-player game element in the game based on game data from the game.
2 . The method according to claim 1 , wherein the updating the hyperparameter values comprises at least one of:
updating first hyperparameter values corresponding to first hyperparameters of some of the first structural blocks to corresponding third hyperparameter values, the third hyperparameter values being the hyperparameter values in the first hyperparameter value subset; and
updating second hyperparameter values corresponding to second hyperparameters of some of the second structural blocks to corresponding fourth hyperparameter values, the fourth hyperparameter values being the hyperparameter values in the second hyperparameter value subset.
3 . The method according to claim 1 , wherein the first hyperparameter comprises a convolution kernel size of a first convolution kernel in convolution kernels comprised in the first structural block, the second hyperparameter comprises a quantity of concatenated second structural blocks, and the determining the hyperparameter values comprises:
determining the convolution kernel size of the first convolution kernel in the first structural block from a third hyperparameter value subset as a target convolution kernel size value; and
determining the quantity of the concatenated second structural blocks from a fourth hyperparameter value subset as a target quantity,
the hyperparameter value set comprising the third hyperparameter value subset and the fourth hyperparameter value subset.
4 . The method according to claim 1 , wherein the obtaining the first model accuracy comprises:
training the first neural network model by using a first training sample set obtained from the target application, to obtain the second neural network model;
detecting, by using the second neural network model, each verification sample in the verification sample set obtained from the target application, to obtain a detection result corresponding to each verification sample in the verification sample set,
the verification sample set comprising a plurality of verification samples obtained from the target application and a target detection result corresponding to each verification sample; and
determining a proportion of a quantity of matches in a total quantity of the plurality of verification samples as the first model accuracy,
the quantity of the matches indicating a quantity of verification samples of which detection results corresponding to the verification samples match target detection results corresponding to the verification samples.
5 . The method according to claim 1 , wherein the method further comprises:
training the third neural network model by using a second training sample set obtained from the target application, to obtain the fourth neural network model.
6 . The method according to claim 5 , wherein the second training sample set comprises scene data and operation data corresponding to the scene data, and the training the third neural network model comprises:
initializing a loss function comprising an input layer, an output layer, a structural layer, and a third neural network model parameter;
inputting the scene data in the second training sample set into the third neural network model in each iterative training process of the third neural network model, to obtain predicted operation data;
substituting the operation data corresponding to the scene data and selected from the second training sample set and the predicted operation data into the loss function, to solve a corresponding third neural network model parameter in a case that a minimum value of the loss function is obtained; and
updating the third neural network model according to the third neural network model parameter that is solved, to obtain the fourth neural network model.
7 . The method according to claim 1 , wherein the input layer comprises a convolutional layer, a batch normalization layer, and an activation layer, the output layer comprises a fully-connected layer and a loss function layer, and the structural layer comprises four layers of first structural blocks and four layers of second structural blocks.
8 . The method according to claim 7 , wherein the first neural network model is obtained by connecting the input layer, the structural layer having the hyperparameter value, and the output layer in the target connection, and the target connection comprises:
concatenating the convolutional layer, the batch normalization layer, and the activation layer, to obtain the input layer;
concatenating the fully-connected layer and the loss function layer to obtain the output layer;
concatenating a first layer of the first structural blocks, a first layer of the second structural blocks, a second layer of the first structural blocks, a second layer of the second structural blocks, a third layer of the first structural blocks, a third layer of the second structural blocks, a fourth layer of the first structural blocks, and a fourth layer of the second structural blocks to obtain the structural layer, the hyperparameter value of the structural layer comprising: a convolution kernel size of each layer of first structural block in the four layers of the first structural blocks, and a quantity of concatenated second structural blocks in each layer of the four layers of the second structural blocks; and
connecting the input layer, the structural layer having the hyperparameter value, and the output layer in a concatenation manner, to obtain the first neural network model.
9 . An apparatus, comprising:
processing circuitry configured to:
determine hyperparameter values for a first neural network model from a hyperparameter value set, the first neural network model comprising an input layer, a structural layer, and an output layer connected in a target connection, the structural layer including a plurality of first structural blocks and a plurality of second structural blocks, the hyperparameter value set including a plurality of first hyperparameter value subsets and a plurality of second hyperparameter value subsets, the plurality of first structural blocks are in a one-to-one correspondence with the plurality of first hyperparameter value subsets, and the plurality of second structural blocks are in a one-to-one correspondence with the plurality of second hyperparameter value subsets, wherein
a first hyperparameter value corresponding to a first hyperparameter, for each of the plurality of first structural blocks, is determined from the corresponding first hyperparameter value subset, and
a second hyperparameter value corresponding to a second hyperparameter, for each of the plurality of second structural blocks, is determined from the corresponding second hyperparameter value subset;
obtain a first model accuracy of a second neural network model by training the first neural network model;
in a case that the first model accuracy is lower than a target accuracy, update hyperparameter values of some hyperparameters in the first neural network model to values from the hyperparameter value set to obtain a third neural network model;
obtain a second model accuracy of a fourth neural network model by training the third neural network model using a verification sample set from a target application; and
determine, based on the fourth neural network model and the second model accuracy being greater than or equal to the target accuracy, operation data that indicates one or more actions to be performed by a non-player game element in a game based on game data from the game.
10 . The apparatus according to claim 9 , wherein the structural layer comprises the first structural block and the second structural block, the first hyperparameter comprises a convolution kernel size of a first convolution kernel in convolution kernels comprised in the first structural block, the second hyperparameter comprises a quantity of concatenated second structural blocks.
11 . The apparatus according to claim 10 , wherein the processing circuitry is further configured to:
determine the convolution kernel size of the first convolution kernel in the first structural block from a third hyperparameter value subset as a target convolution kernel size value; and
determine the quantity of the concatenated second structural blocks from a fourth hyperparameter value subset as a target quantity,
the hyperparameter value set comprising the third hyperparameter value subset and the fourth hyperparameter value subset.
12 . The apparatus according to claim 9 , wherein the processing circuitry is further configured to:
train the third neural network model by using a second training sample set obtained from the target application, to obtain the fourth neural network model.
13 . A non-transitory computer-readable medium storing instructions which when executed by at least one processor cause the at least one processor to perform:
determining hyperparameter values for a first neural network model from a hyperparameter value set, the first neural network model comprising an input layer, a structural layer, and an output layer connected in a target connection, the structural layer including a plurality of first structural blocks and a plurality of second structural blocks, the hyperparameter value set including a plurality of first hyperparameter value subsets and a plurality of second hyperparameter value subsets, the plurality of first structural blocks are in a one-to-one correspondence with the plurality of first hyperparameter value subsets, and the plurality of second structural blocks are in a one-to-one correspondence with the plurality of second hyperparameter value subsets, wherein
a first hyperparameter value corresponding to a first hyperparameter, for each of the plurality of first structural blocks, is determined from the corresponding first hyperparameter value subset, and
a second hyperparameter value corresponding to a second hyperparameter, for each of the plurality of second structural blocks, is determined from the corresponding second hyperparameter value subset;
obtaining a first model accuracy of a second neural network model by training the first neural network model;
in a case that the first model accuracy is lower than a target accuracy, updating hyperparameter values of some hyperparameters in the first neural network model to values from the hyperparameter value set to obtain a third neural network model;
obtaining a second model accuracy of a fourth neural network model by training the third neural network model using a verification sample set from a target application; and
determining, based on the fourth neural network model and the second model accuracy being greater than or equal to the target accuracy, operation data that indicates one or more actions to be performed by a non-player game element in a game based on game data from the game.
14 . The non-transitory computer-readable medium according to claim 13 , wherein the instructions further cause the at least one processor to perform:
training the third neural network model by using a second training sample set obtained from the target application, to obtain the fourth neural network model.