Iam trying to change this code from tensorflow to pytorch but i cant

if someone can help me it would be fantastic, I can send you the code

Could you post the code you have trouble with here and explain what you’ve tried so far and where you are stuck?

def inference_batch(self, images=None, target_ys=None, scale=None, par_inp=None):

    """Report loss and label probabilities, and patched images for a batch.

	Args:
	  images: A batch of images to train on, it loads if not present.
	  target_ys: The target_ys for loss calculation, TARGET_ONEHOT if not present."""
    if images is None:
        images = image_loader.get_images()

    if target_ys is None:
        target_ys = TARGET_ONEHOT
    if par_inp is None:
        par_inp = [1., 0.]

    feed_dict = {self._image_input: images, self._target_ys: target_ys, self._par_inp: par_inp, }
    loss_per_example, ps, ims, output_layer = self._run([self._loss_per_example,
                                                         self._probabilities, self._inp,
                                                         # self._patched_input,
                                                         self.ouput_layer],
                                                        feed_dict, scale=scale)

    return loss_per_example, ps, ims, output_layer

I have tried to change this function from tensor flow to pytorch but with no good results

Your code snippet only shows a TF session being executed. PyTorch does not use sessions or other objects to “run” the model, but can execute code directly, similar to e.g. numpy. You can just run the forward pass of a model by passing an input to it:

# create model instance
model = models.resnet18()

# create random inputs
x = torch.randn(1, 3, 224, 224)

# execute forward pass
output = model(x)

# compute gradients in backward pass
output.mean().backward()

This tutoral might be helpful to get started.