Skip to content

Instantly share code, notes, and snippets.

View shivanandmn's full-sized avatar

Shivanand shivanandmn

View GitHub Profile
@shivanandmn
shivanandmn / images2dataframe.py
Last active April 14, 2024 20:21
Convert any image to 784(28*28) grayscale pixel dataframe.
import pandas as pd
import numpy as np
import cv2
image_files = pd.DataFrame(columns=range(784)).add_prefix('pixels_')
for i in range(1, 6):
r_image = cv2.imread(f'images/{i}.JPG')
numpy_image = cv2.cvtColor(r_image, cv2.COLOR_BGR2GRAY)
image = cv2.resize(numpy_image, (28, 28)).astype(np.float32)
image = image.reshape(-1)
image_files.loc[f'image_{i}', 'pixels_0':] = image
class LightningModel(pl.LightningModule):
def __init__(self):
super().__init__()
def forward(self,x):
pass
def configure_optimizers(self):
pass
class LightningDataModule(pl.LightningDataModule):
def __init__(self):
super().__init__()
def prepare_data(self):
pass
def setup(self,stage=None):
pass
dataset = LightningDataModule()
pl_model = LightningModel()
trainer = pl.Trainer(max_epochs=10)
trainer.fit(model=pl_model,datamodule=dataset)
#trainer.test(test_dataset)
@shivanandmn
shivanandmn / rename_files.py
Created December 5, 2020 02:37
Changing the list of PDFs files from directory by using digit-only
# changing the names of the files in a directory
import os
import re
path = os.getcwd()
k = os.listdir(path)
for files in k:
x = re.search("\d+", files)
if x is None:
continue
@shivanandmn
shivanandmn / compile_makefile.py
Created December 18, 2020 02:48
Compile makefile in google collab using Boost.
#install boost library
!sudo apt-get install libboost-dev
#boost-root or boost-include-directory may be here /usr/include/boost
####follow below with example
"""Consider your installing mesh from https://github.com/MPI-IS/mesh, it has makefile(filename:makefile)"""
#--Cloning repository
!git clone https://github.com/MPI-IS/mesh.git
#--Providing permission to admin rights
!chmod 755 /content/mesh/Makefile
#--move to its project root directory by following command
@shivanandmn
shivanandmn / download_from_kaggle_api..py
Last active February 25, 2021 23:43
Download the Kaggle Dataset via API in Google Colab Directly.
#install upgraded to get full-dataset, otherwise you may get sample of it.
!pip install -q kaggle==1.5.6
#upload kaggle.json file
from google.colab import files
files.upload()
#must create ~/.kaggle directory and copy kaggle.json to it.
!mkdir ~/.kaggle
!cp kaggle.json ~/.kaggle
@shivanandmn
shivanandmn / dlib_face_landmarks.py
Created March 5, 2021 00:43
Detecting face and landmarks from image using dlib and opencv
#pip install dlib
#download pretrained dlib file and unzip
#$wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
#$bzip2 -d /content/shape_predictor_68_face_landmarks.dat.bz2
import sys
import numpy as np
import cv2
#below line of code is used only in colab
from google.colab.patches import cv2_imshow
@shivanandmn
shivanandmn / web_browser.py
Created May 24, 2021 13:05
Open URL directly in browser from python code.
import webbrowser
import pandas as pd
df = pd.read_csv("sub.csv")
for i in df["files"].values.tolist():
urls = "http://127.0.0.1:5000/question/"+str(i[:-3])
#opens url in default browser, you can also use open_tab()
webbrowser.get().open(url=urls)
@shivanandmn
shivanandmn / git basic commands
Last active June 28, 2021 04:08
Basic git commands I am learning while at work.
git branch -a #get all branch
git checkout master #get to the master branch
git checkout -b new_branch #(create and get) new branch
git push -u origin new_branch #push changes to new_branch to repo. for first push -u will set upstream/tracker.
git pull origin guru #pull the repo from guru branch
git add . # add present changes
git commit -m "fdhkfjd" # commit all the added changes.
git push origin guru #then push it