Skip to content

Commit

Permalink
🐛 Make torchvision import lazily in CRAFT model code
Browse files Browse the repository at this point in the history
  • Loading branch information
arxyzan committed Oct 29, 2024
1 parent af1389f commit c10f0c0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions hezar/models/text_detection/craft/craft_text_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models

from ....constants import Backends
from ....registry import register_model
from ....utils import is_backend_available
from ...model import Model
from ...model_outputs import TextDetectionOutput
from .craft_text_detection_config import CraftTextDetectionConfig
from .craft_utils import adjust_result_coordinates, get_detection_boxes, polys2boxes


if is_backend_available(Backends.TORCHVISION):
from torchvision.models import vgg16_bn

_required_backends = [
Backends.OPENCV,
Backends.PILLOW,
Expand Down Expand Up @@ -141,7 +144,7 @@ def post_process(
class VGG16BN(nn.Module):
def __init__(self):
super(VGG16BN, self).__init__()
vgg_pretrained_features = models.vgg16_bn().features
vgg_pretrained_features = vgg16_bn().features

self.slice1 = nn.Sequential()
self.slice2 = nn.Sequential()
Expand Down

0 comments on commit c10f0c0

Please sign in to comment.