Skip to content

Instantly share code, notes, and snippets.

@kurianbenoy
Last active April 10, 2022 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurianbenoy/8861f69c684ec093db7f87ce129ffb23 to your computer and use it in GitHub Desktop.
Save kurianbenoy/8861f69c684ec093db7f87ce129ffb23 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"! pip install -Uqq fastai","metadata":{"execution":{"iopub.status.busy":"2022-04-10T18:30:51.772212Z","iopub.execute_input":"2022-04-10T18:30:51.772766Z","iopub.status.idle":"2022-04-10T18:31:11.032122Z","shell.execute_reply.started":"2022-04-10T18:30:51.772678Z","shell.execute_reply":"2022-04-10T18:31:11.031273Z"},"trusted":true},"execution_count":1,"outputs":[]},{"cell_type":"code","source":"from fastai.vision.all import *","metadata":{"execution":{"iopub.status.busy":"2022-04-10T18:31:11.034444Z","iopub.execute_input":"2022-04-10T18:31:11.034725Z","iopub.status.idle":"2022-04-10T18:31:13.558322Z","shell.execute_reply.started":"2022-04-10T18:31:11.034689Z","shell.execute_reply":"2022-04-10T18:31:13.557530Z"},"trusted":true},"execution_count":2,"outputs":[]},{"cell_type":"code","source":"import fastai\nfastai.__version__","metadata":{"execution":{"iopub.status.busy":"2022-04-10T18:31:13.559793Z","iopub.execute_input":"2022-04-10T18:31:13.560060Z","iopub.status.idle":"2022-04-10T18:31:13.567436Z","shell.execute_reply.started":"2022-04-10T18:31:13.560025Z","shell.execute_reply":"2022-04-10T18:31:13.566756Z"},"trusted":true},"execution_count":3,"outputs":[]},{"cell_type":"code","source":"#hide_output\npath = untar_data(URLs.PETS)/'images'\n\ndef is_cat(x): \n return x[0].isupper() # if filename is Capitalized, its a cat image\n\ndls = ImageDataLoaders.from_name_func(\n path, # where our image are\n get_image_files(path), # how to build our inputs (our x)\n label_func=is_cat, # how to build our labels (our y)\n valid_pct=0.2, # how to build our validation set\n item_tfms=Resize(224), # things we want to do to each image when we fetch it\n seed=42 # for reproducibility\n)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T18:31:13.569523Z","iopub.execute_input":"2022-04-10T18:31:13.570054Z","iopub.status.idle":"2022-04-10T18:31:39.213423Z","shell.execute_reply.started":"2022-04-10T18:31:13.570014Z","shell.execute_reply":"2022-04-10T18:31:39.212597Z"},"trusted":true},"execution_count":4,"outputs":[]},{"cell_type":"code","source":"learn = cnn_learner(dls, resnet18, metrics=error_rate)\nlearn.fine_tune(1)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T18:31:39.214942Z","iopub.execute_input":"2022-04-10T18:31:39.215206Z","iopub.status.idle":"2022-04-10T18:33:26.067209Z","shell.execute_reply.started":"2022-04-10T18:31:39.215168Z","shell.execute_reply":"2022-04-10T18:33:26.066397Z"},"trusted":true},"execution_count":5,"outputs":[]},{"cell_type":"code","source":"learn.export(fname=\"model.pkl\")","metadata":{"execution":{"iopub.status.busy":"2022-04-10T18:35:25.359204Z","iopub.execute_input":"2022-04-10T18:35:25.359505Z","iopub.status.idle":"2022-04-10T18:35:25.483987Z","shell.execute_reply.started":"2022-04-10T18:35:25.359467Z","shell.execute_reply":"2022-04-10T18:35:25.483224Z"},"trusted":true},"execution_count":8,"outputs":[]},{"cell_type":"code","source":"path = Path()\npath.ls(file_exts='.pkl')","metadata":{"execution":{"iopub.status.busy":"2022-04-10T18:37:48.769601Z","iopub.execute_input":"2022-04-10T18:37:48.770259Z","iopub.status.idle":"2022-04-10T18:37:48.777063Z","shell.execute_reply.started":"2022-04-10T18:37:48.770226Z","shell.execute_reply":"2022-04-10T18:37:48.776348Z"},"trusted":true},"execution_count":10,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}
@kurianbenoy
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment