Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(string_t), | intent(in) | :: | output_file_name |
subroutine write_read_query_infer(output_file_name) type(string_t), intent(in) :: output_file_name type(string_t) activation_name integer i, j integer, parameter :: num_neurons = 3, num_hidden_layers = 2 type(neural_network_t) network, neural_network type(file_t) json_output_file, json_input_file type(tensor_t) inputs, outputs print *, "Constructing a neural_network_t neural-network object from scratch." network = identity_network() print *, "Converting a neural_network_t object to a file_t object." json_output_file = network%to_json() print *, "Writing a neural_network_t object to the file '"//output_file_name%string()//"' in JSON format." call json_output_file%write_lines(output_file_name) print *, "Reading a neural_network_t object from the same JSON file '"//output_file_name%string()//"'." json_input_file = file_t(output_file_name) print *, "Constructing a new neural_network_t object from the parameters read." neural_network = neural_network_t(json_input_file) print *, "Querying the new neural_network_t object for several properties:" print *, "Number of outputs:", neural_network%num_outputs() print *, "Number of inputs:", neural_network%num_inputs() print *, "Nodes per layer:", neural_network%nodes_per_layer() activation_name = neural_network%activation_function_name() print *, "Activation function: ", activation_name%string() print *, "Performing inference:" inputs = tensor_t([2.,3.]) print *, "Inputs: ", inputs%values() outputs = neural_network%infer(inputs) print *, "Actual outputs: ", outputs%values() print *, "Correct outputs: ", inputs%values() end subroutine write_read_query_infer