File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 55from torchvision import models
66from PIL import Image
77
8+ # Make sure to pass `pretrained` as `True` to use the pretrained weights:
9+ model = models .densenet121 (pretrained = True )
10+ # Since we are using our model only for inference, switch to `eval` mode:
11+ model .eval ()
12+
813
914def transform_image (image_bytes ):
1015 my_transforms = transforms .Compose ([transforms .Resize (255 ),
@@ -26,11 +31,6 @@ def supported_image_type(img):
2631def predict (image_file , class_file ):
2732 try :
2833 class_file = getcwd () + '/flask_pytorch_web_app/' + class_file
29- # Make sure to pass `pretrained` as `True` to use the pretrained weights:
30- model = models .densenet121 (pretrained = True )
31- # Since we are using our model only for inference, switch to `eval` mode:
32- model .eval ()
33-
3434 imagenet_class_index = json .load (open (class_file ))
3535 with open (image_file , 'rb' ) as f :
3636 image_bytes = f .read ()
@@ -50,3 +50,4 @@ def test():
5050
5151 p = predict (img , cf )
5252 print (f'Given image is: { p [1 ]} ' )
53+
You can’t perform that action at this time.
0 commit comments