-
-
Save amankharwal/448a7f3382f0bc11d273dbd1a5cf14e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import LabelEncoder | |
lencoder = LabelEncoder() | |
lencoder.fit(df["landmark_id"]) | |
def encode_label(lbl): | |
return lencoder.transform(lbl) | |
def decode_label(lbl): | |
return lencoder.inverse_transform(lbl) | |
def get_image_from_number(num): | |
fname, label = df.loc[num,:] | |
fname = fname + ".jpg" | |
f1 = fname[0] | |
f2 = fname[1] | |
f3 = fname[2] | |
path = os.path.join(f1,f2,f3,fname) | |
im = cv2.imread(os.path.join(base_path,path)) | |
return im, label | |
print("4 sample images from random classes:") | |
fig=plt.figure(figsize=(16, 16)) | |
for i in range(1,5): | |
a = random.choices(os.listdir(base_path), k=3) | |
folder = base_path+'/'+a[0]+'/'+a[1]+'/'+a[2] | |
random_img = random.choice(os.listdir(folder)) | |
img = np.array(Image.open(folder+'/'+random_img)) | |
fig.add_subplot(1, 4, i) | |
plt.imshow(img) | |
plt.axis('off') | |
plt.show() |
base_path is not defined at line 24. Any fix?
base_path is not defined
Hi from future(2023) lol. Do you remember having a fix for that?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
base_path is not defined