TensorFlow graph data failed to import

19 Views Asked by At

I was recently learning about Aesara and TensorFlow 2, and I couldn't successfully import data when I tried to open computational graphs

This is the original text of Aesara's code

    def compile_th_fn_geo(self, inplace=False, debug=True, grid: Union[str, np.ndarray] = None):
        """
        Compile and create the aesara function which can be evaluated to compute the geological models

        Args:

            inplace (bool): If true add the attribute aesara.function to the object inplace
            debug (bool): If true print some of the aesara flags
            grid: If None, grid will be passed as variable. If shared or np.ndarray the grid will be treated as
             constant (if shared the grid will be taken of grid)

        Returns:
            aesara.function: function that computes the whole interpolation
        """

        self.set_all_shared_parameters(reset_ctrl=False)
        # This are the shared parameters and the compilation of the function. This will be hidden as well at some point
        input_data_T = self.aesara_graph.input_parameters_loop
        print('Compiling aesara function...')
        if grid == 'shared' or grid is not None:
            self.set_aesara_shared_grid(grid)

        th_fn = aesara.function(inputs=input_data_T,
                                outputs=self.aesara_graph.aesara_output(),
                                updates=[
                                    (self.aesara_graph.block_matrix, self.aesara_graph.new_block),
                                    (self.aesara_graph.weights_vector,
                                     self.aesara_graph.new_weights),
                                    (self.aesara_graph.scalar_fields_matrix,
                                     self.aesara_graph.new_scalar),
                                    (self.aesara_graph.mask_matrix, self.aesara_graph.new_mask)
                                ],
                                on_unused_input='ignore',
                                allow_input_downcast=False,
                                profile=False)

        if inplace is True:
            self.aesara_function = th_fn

        if debug is True:
            print('Level of Optimization: ', aesara.config.optimizer)
            print('Device: ', aesara.config.device)
            print('Precision: ', aesara.config.floatX)
            print('Number of faults: ',
                  self.additional_data.structure_data.df.loc['values', 'number faults'])
        print('Compilation Done!')

This is the tensorflow code I converted

@tf.function
    def compile_tf_fn_geo(self, inplace=False, debug=True, grid: Union[str, np.ndarray] = None):
        """
        Compile and create the TensorFlow function which can be evaluated to compute the geological models

        Args:
            inplace (bool): If true add the attribute tensorflow_function to the object inplace
            debug (bool): If true print some of the TensorFlow flags
            grid: If None, grid will be passed as a variable. If shared or np.ndarray the grid will be treated as
                  constant (if shared the grid will be taken from grid)

        Returns:
            tensorflow.function: function that computes the whole interpolation
        """

        self.set_all_shared_parameters(reset_ctrl=False)
        # This are the shared parameters and the compilation of the function. This will be hidden as well at some point
        input_data_T = self.tensorflow_graph.input_parameters_loop
        print('Compiling TensorFlow function...')
        if grid == 'shared' or grid is not None:
            self.set_tensorflow_shared_grid(grid)

        # Assuming self.tensorflow_graph.tensorflow_output() returns the output tensor
        output_tensor = self.tensorflow_graph.tensorflow_output()

        if inplace is True:
            self.tensorflow_function = tf.function(self.tensorflow_graph.tensorflow_output)

        if debug is True:
            print('Number of faults: ',
                  self.additional_data.structure_data.df.loc['values', 'number faults'])
        print('Compilation Done!')
        return output_tensor

Where did the problem cause no values to import when the graph was running?Please help me.Thanks!

0

There are 0 best solutions below