gmustafa413 commited on
Commit
229e730
·
verified ·
1 Parent(s): 8a3ec9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -70,7 +70,7 @@ class resnet_feature_extractor(torch.nn.Module):
70
 
71
 
72
 
73
- image = Image.open(r'/content/carpet/test/color/000.png')
74
  image = transform(image).unsqueeze(0)
75
 
76
  backbone = resnet_feature_extractor()
@@ -85,7 +85,7 @@ print(feature.shape)
85
 
86
  memory_bank =[]
87
 
88
- folder_path = Path(r'/content/carpet/train/good')
89
 
90
  for pth in tqdm(folder_path.iterdir(),leave=False):
91
  with torch.no_grad():
@@ -97,7 +97,7 @@ memory_bank = torch.cat(memory_bank,dim=0)
97
 
98
  y_score=[]
99
 
100
- folder_path = Path(r'/content/carpet/train/good')
101
 
102
  for pth in tqdm(folder_path.iterdir(),leave=False):
103
  data = transform(Image.open(pth)).unsqueeze(0)
@@ -123,7 +123,7 @@ y_score = []
123
  y_true=[]
124
 
125
  for classes in ['color','good','cut','hole','metal_contamination','thread']:
126
- folder_path = Path(r'/content/carpet/test/{}'.format(classes))
127
 
128
  for pth in tqdm(folder_path.iterdir(),leave=False):
129
 
@@ -150,7 +150,7 @@ plt.vlines(x=best_threshold,ymin=0,ymax=30,color='r')
150
  plt.show()
151
 
152
 
153
- test_image = transform(Image.open(r'/content/carpet/test/color/000.png')).unsqueeze(0)
154
  features = backbone(test_image)
155
 
156
  distances = torch.cdist(features, memory_bank, p=2.0)
 
70
 
71
 
72
 
73
+ image = Image.open(r'carpet/test/color/000.png')
74
  image = transform(image).unsqueeze(0)
75
 
76
  backbone = resnet_feature_extractor()
 
85
 
86
  memory_bank =[]
87
 
88
+ folder_path = Path(r'carpet/train/good')
89
 
90
  for pth in tqdm(folder_path.iterdir(),leave=False):
91
  with torch.no_grad():
 
97
 
98
  y_score=[]
99
 
100
+ folder_path = Path(r'carpet/train/good')
101
 
102
  for pth in tqdm(folder_path.iterdir(),leave=False):
103
  data = transform(Image.open(pth)).unsqueeze(0)
 
123
  y_true=[]
124
 
125
  for classes in ['color','good','cut','hole','metal_contamination','thread']:
126
+ folder_path = Path(r'carpet/test/{}'.format(classes))
127
 
128
  for pth in tqdm(folder_path.iterdir(),leave=False):
129
 
 
150
  plt.show()
151
 
152
 
153
+ test_image = transform(Image.open(r'carpet/test/color/000.png')).unsqueeze(0)
154
  features = backbone(test_image)
155
 
156
  distances = torch.cdist(features, memory_bank, p=2.0)