привет смотри у меня есть такой код
import tensorflow as tf
import os

def conv1x1(in_planes, out_planes, stride=1):
    """1x1 свертка без паддинга."""
    return tf.keras.layers.Conv2D(
        filters=out_planes,
        kernel_size=1,
        strides=stride,
        padding='valid',
        use_bias=False)


def conv3x3(in_planes, out_planes, stride=1):
    """3x3 свертка с паддингом."""
    return tf.keras.layers.Conv2D(
        filters=out_planes,
        kernel_size=3,
        strides=stride,
        padding='same',
        use_bias=False)


class BasicBlock(tf.keras.layers.Layer):
    def __init__(self, in_planes, planes, stride=1):
        super(BasicBlock, self).__init__()
        self.conv1 = conv3x3(in_planes, planes, stride=stride)
        self.bn1 = tf.keras.layers.BatchNormalization()
        self.relu = tf.keras.layers.ReLU()
        self.conv2 = conv3x3(planes, planes)
        self.bn2 = tf.keras.layers.BatchNormalization()

        if stride != 1 or in_planes != planes:
            self.downsample = tf.keras.Sequential([
                conv1x1(in_planes, planes, stride=stride),
                tf.keras.layers.BatchNormalization(),
            ])
        else:
            self.downsample = None

    def call(self, x, training=False):
        identity = x

        y = self.conv1(x)
        y = self.bn1(y, training=training)
        y = self.relu(y)
        y = self.conv2(y)
        y = self.bn2(y, training=training)

        if self.downsample is not None:
            identity = self.downsample(identity, training=training)

        out = self.relu(tf.keras.layers.add([identity, y]))
        return out


class ResNetFPN_8_2(tf.keras.Model):
    """ResNet+FPN, выходные разрешения 1/8 и 1/2."""

    def __init__(self):
        super(ResNetFPN_8_2, self).__init__()

        initial_dim = 128
        block_dims = [128, 196, 256]
        Block = BasicBlock

        self.in_planes = initial_dim

        # Начальный сверточный слой
        self.conv1 = tf.keras.layers.Conv2D(
            filters=initial_dim,
            kernel_size=7,
            strides=2,
            padding='same',
            use_bias=False
        )
        self.bn1 = tf.keras.layers.BatchNormalization()
        self.relu = tf.keras.layers.ReLU()

        # Слои ResNet
        self.layer1 = self._make_layer(Block, block_dims[0], stride=1)
        self.layer2 = self._make_layer(Block, block_dims[1], stride=2)
        self.layer3 = self._make_layer(Block, block_dims[2], stride=2)

        # FPN upsample
        self.layer3_outconv = conv1x1(block_dims[2], block_dims[2])
        self.layer2_outconv = conv1x1(block_dims[1], block_dims[2])
        self.layer2_outconv2 = tf.keras.Sequential([
            conv3x3(block_dims[2], block_dims[2]),
            tf.keras.layers.BatchNormalization(),
            tf.keras.layers.ReLU(),
            conv3x3(block_dims[2], block_dims[1]),
        ])
        self.layer1_outconv = conv1x1(block_dims[0], block_dims[1])
        self.layer1_outconv2 = tf.keras.Sequential([
            conv3x3(block_dims[1], block_dims[1]),
            tf.keras.layers.BatchNormalization(),
            tf.keras.layers.ReLU(),
            conv3x3(block_dims[1], block_dims[0]),
        ])

        # Финальные слои для преобразования в 1 канал
        self.final_conv_x3 = tf.keras.layers.Conv2D(
            filters=1,
            kernel_size=1,
            padding='same',
            activation='sigmoid'  # Используйте активацию по необходимости
        )
        self.final_conv_x1 = tf.keras.layers.Conv2D(
            filters=1,
            kernel_size=1,
            padding='same',
            activation='sigmoid'
        )

    def _make_layer(self, block, planes, stride=1):
        layers = []
        layers.append(block(self.in_planes, planes, stride=stride))
        self.in_planes = planes
        layers.append(block(self.in_planes, planes, stride=1))
        return tf.keras.Sequential(layers)

    def call(self, x, training=False):
        # ResNet Backbone
        x0 = self.conv1(x)
        x0 = self.bn1(x0, training=training)
        x0 = self.relu(x0)

        x1 = self.layer1(x0, training=training)  # 1/2
        x2 = self.layer2(x1, training=training)  # 1/4
        x3 = self.layer3(x2, training=training)  # 1/8

        # FPN
        x3_out = self.layer3_outconv(x3)

        x2_out = self.layer2_outconv(x2)
        x3_out_2x = tf.image.resize(
            x3_out,
            size=tf.shape(x2_out)[1:3],
            method='bilinear'
        )
        x2_out = x2_out + x3_out_2x
        x2_out = self.layer2_outconv2(x2_out, training=training)

        x1_out = self.layer1_outconv(x1)
        x2_out_2x = tf.image.resize(
            x2_out,
            size=tf.shape(x1_out)[1:3],
            method='bilinear'
        )
        x1_out = x1_out + x2_out_2x
        x1_out = self.layer1_outconv2(x1_out, training=training)

        x3_out = self.final_conv_x3(x3_out)
        x1_out = self.final_conv_x1(x1_out)

        return [x3_out, x1_out]


# Определение модели
model = ResNetFPN_8_2()

# Определение входной формы
input_shape = (1, 250, 200, 1)
input_image = tf.random.uniform(input_shape)

# Передача входных данных для построения модели
outputs = model(input_image, training=False)

# **Исправление здесь:**
# Сохранение модели в формате SavedModel
model.save('saved_model.keras')
model.export("model")

# Преобразование SavedModel в TensorFlow Lite
converter = tf.lite.TFLiteConverter.from_saved_model('model')
converter.target_spec.supported_ops = [
    tf.lite.OpsSet.TFLITE_BUILTINS,  # Встроенные операции TFLite
    tf.lite.OpsSet.SELECT_TF_OPS     # Операции TensorFlow
]

DATA_DIR = 'data'

# Define image size and channels based on your model's input shape
IMG_HEIGHT = 250
IMG_WIDTH = 200
IMG_CHANNELS = 1

def representative_dataset_gen():
    for image_name in os.listdir(DATA_DIR):
        image_path = os.path.join(DATA_DIR, image_name)
        # Load and preprocess the image
        image = tf.io.read_file(image_path)
        image = tf.image.decode_image(image, channels=IMG_CHANNELS)
        image = tf.image.resize(image, [IMG_HEIGHT, IMG_WIDTH])
        image = tf.cast(image, tf.float32)
        # Normalize the image if your model expects normalized inputs
        image = image / 255.0
        # Add batch dimension
        image = tf.expand_dims(image, axis=0)
        yield [image]


converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset_gen
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.target_spec.supported_types = [tf.int8]
converter.inference_type = tf.int8
converter.inference_input_type = tf.int8
converter.inference_output_type = tf.int8


tflite_model = converter.convert()

# Сохранение модели TensorFlow Lite в файл
with open('model_data.tflite', 'wb') as f:
    f.write(tflite_model)





я хочу помимо того, то собираю модель вставлять ей веса из ckpt файла. У меня есть код этой модели на pytorch и файл весов ckpt, я хочу встроить эти веса в свою модель tensorflow
import numpy
import torch
import torch.nn as nn
import kornia as K
from typing import Any, Dict, List, Type, Union
import cv2
import torch.nn.functional as F
import torch.onnx
#from torchsummary import summary
import onnx
from onnx_tf.backend import prepare
import numpy as np
from PIL import Image
#from IPython.display import display
import onnxruntime as ort
import tensorflow as tf

Module = torch.nn.Module
Tensor = torch.Tensor

def load_torch_image(fname):
    img = K.image_to_tensor(cv2.imread(fname), False).float() / 255
    img = K.color.bgr_to_rgb(img)
    img = K.color.rgb_to_grayscale(img)
    return img



def conv1x1(in_planes: int, out_planes: int, stride: int = 1) -> nn.Conv2d:
    """1x1 convolution without padding."""
    return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, padding=0, bias=False)


def conv3x3(in_planes: int, out_planes: int, stride: int = 1) -> nn.Conv2d:
    """3x3 convolution with padding."""
    return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=False)


class BasicBlock(Module):
    def __init__(self, in_planes: int, planes: int, stride: int = 1) -> None:
        super().__init__()
        self.conv1 = conv3x3(in_planes, planes, stride)
        self.conv2 = conv3x3(planes, planes)
        self.bn1 = nn.BatchNorm2d(planes)
        self.bn2 = nn.BatchNorm2d(planes)
        self.relu = nn.ReLU(inplace=True)

        if stride == 1:
            self.downsample = None
        else:
            self.downsample = nn.Sequential(conv1x1(in_planes, planes, stride=stride), nn.BatchNorm2d(planes))

    def forward(self, x: Tensor) -> Tensor:
        y = x
        y = self.relu(self.bn1(self.conv1(y)))
        y = self.bn2(self.conv2(y))

        if self.downsample is not None:
            x = self.downsample(x)

        return self.relu(x + y)

class ResNetFPN_8_2(nn.Module):
    """ResNet+FPN, output resolution are 1/8 and 1/2.

    Each block has 2 layers.
    """

    def __init__(self) -> None:
        super().__init__()
        # Config
        block = BasicBlock
        initial_dim = 128
        block_dims = [128,196,256]

        # Class Variable
        self.in_planes = initial_dim

        # Networks
        self.conv1 = nn.Conv2d(1, initial_dim, kernel_size=7, stride=2, padding=3, bias=False)
        self.bn1 = nn.BatchNorm2d(initial_dim)
        self.relu = nn.ReLU(inplace=True)

        self.layer1 = self._make_layer(block, block_dims[0], stride=1)  # 1/2
        self.layer2 = self._make_layer(block, block_dims[1], stride=2)  # 1/4
        self.layer3 = self._make_layer(block, block_dims[2], stride=2)  # 1/8

        # 3. FPN upsample
        self.layer3_outconv = conv1x1(block_dims[2], block_dims[2])
        self.layer2_outconv = conv1x1(block_dims[1], block_dims[2])
        self.layer2_outconv2 = nn.Sequential(
            conv3x3(block_dims[2], block_dims[2]),
            nn.BatchNorm2d(block_dims[2]),
            nn.ReLU(inplace=True),#nn.LeakyReLU(),
            conv3x3(block_dims[2], block_dims[1]),
        )
        self.layer1_outconv = conv1x1(block_dims[0], block_dims[1])
        self.layer1_outconv2 = nn.Sequential(
            conv3x3(block_dims[1], block_dims[1]),
            nn.BatchNorm2d(block_dims[1]),
            nn.ReLU(inplace=True),#nn.LeakyReLU(),
            conv3x3(block_dims[1], block_dims[0]),
        )

        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode="fan_out", nonlinearity="relu")
            elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)

    def _make_layer(self, block: Union[Type[BasicBlock], Module], dim: int, stride: int = 1) -> nn.Sequential:
        layer1 = block(self.in_planes, dim, stride=stride)
        layer2 = block(dim, dim, stride=1)
        layers = (layer1, layer2)

        self.in_planes = dim
        return nn.Sequential(*layers)

    def forward(self, x: Tensor) -> List[Tensor]:
        # ResNet Backbone
        x0 = self.relu(self.bn1(self.conv1(x)))
        x1 = self.layer1(x0)  # 1/2
        x2 = self.layer2(x1)  # 1/4
        x3 = self.layer3(x2)  # 1/8

        # FPN
        x3_out = self.layer3_outconv(x3)

        x2_out = self.layer2_outconv(x2)
        x3_out_2x = F.interpolate(x3_out, size=(x2_out.shape[2:]), mode="bilinear", align_corners=True)
        x2_out = self.layer2_outconv2(x2_out + x3_out_2x)

        x1_out = self.layer1_outconv(x1)
        x2_out_2x = F.interpolate(x2_out, size=(x1_out.shape[2:]), mode="bilinear", align_corners=True)
        x1_out = self.layer1_outconv2(x1_out + x2_out_2x)

        return [x3_out, x1_out]