Spaces:
Runtime error
Runtime error
Delete Classifier (1).ipynb
Browse files- Classifier (1).ipynb +0 -1
Classifier (1).ipynb
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"mount_file_id":"1uigl2RNXRWvhFzIoe9ipnRFOoAjFaiGy","authorship_tag":"ABX9TyO/vHvztPXsgmNlRl3ny9iK"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","source":["pip install gradio jinja2"],"metadata":{"id":"1GlzZ9BiFIE3"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["import torchvision.models as models\n","from torchvision import transforms\n","import torch\n","\n","import os\n","import gradio as gr\n"],"metadata":{"id":"8qQwFM6lKJYM","executionInfo":{"status":"ok","timestamp":1692822480256,"user_tz":-60,"elapsed":6831,"user":{"displayName":"Minhajul Nokib","userId":"12885952758206578993"}}},"execution_count":8,"outputs":[]},{"cell_type":"code","execution_count":2,"metadata":{"id":"CLwexxhlKDsv","executionInfo":{"status":"ok","timestamp":1692822336807,"user_tz":-60,"elapsed":3,"user":{"displayName":"Minhajul Nokib","userId":"12885952758206578993"}}},"outputs":[],"source":["class Model_resnet(nn.Module):\n"," def __init__(self):\n"," super(Model_resnet,self).__init__()\n"," self.model = models.resnet18(pretrained = True)\n"," for param in self.model.parameters():\n"," param.require_grad = False\n"," for param in self.model.fc.parameters():\n"," param.require_grad = True\n"," self.model.fc = nn.Linear(in_features=512,out_features=2)\n"," def forward(self,x):\n"," x = self.model(x)\n"," return x\n"]},{"cell_type":"code","source":["model = torch.load(\"CCD_Model.pth\")\n"],"metadata":{"id":"93D4Jv38NHZe","executionInfo":{"status":"ok","timestamp":1692822339660,"user_tz":-60,"elapsed":2070,"user":{"displayName":"Minhajul Nokib","userId":"12885952758206578993"}}},"execution_count":3,"outputs":[]},{"cell_type":"code","source":["optimizer = torch.optim.Adam([parameters for parameters in model.parameters() if parameters.requires_grad],lr=0.001)"],"metadata":{"id":"8cGQY8Ey8Jiw","executionInfo":{"status":"ok","timestamp":1692822339661,"user_tz":-60,"elapsed":2,"user":{"displayName":"Minhajul Nokib","userId":"12885952758206578993"}}},"execution_count":4,"outputs":[]},{"cell_type":"code","source":["model.eval()"],"metadata":{"id":"FxYJKoZaJqNX"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["def classify(img):\n"," mean = [0.485, 0.456, 0.406]\n"," std = [0.229, 0.224, 0.225]\n","\n","\n"," transform = transforms.Compose([transforms.ToTensor(),transforms.Normalize(mean,std)])\n","\n","\n","\n"," tr_image = transform(img)\n"," X = tr_image.reshape(-1,3,224,224)\n"," y = model(X)\n"," _,yhat = torch.max(y.data,1)\n"," if yhat.item() == 1:\n"," text = \"cracked\"\n"," else:\n"," text = \"not cracked\"\n","\n"," return text\n","\n"],"metadata":{"id":"VGKyI37wKwRX","executionInfo":{"status":"ok","timestamp":1692823601483,"user_tz":-60,"elapsed":299,"user":{"displayName":"Minhajul Nokib","userId":"12885952758206578993"}}},"execution_count":21,"outputs":[]},{"cell_type":"code","source":["gr.Interface(fn=classify,\n"," inputs=gr.Image(shape=(224, 224)),\n"," outputs='text').launch(share = True)"],"metadata":{"id":"6uM1BxXcN0eP","executionInfo":{"status":"ok","timestamp":1692824445508,"user_tz":-60,"elapsed":14625,"user":{"displayName":"Minhajul Nokib","userId":"12885952758206578993"}},"colab":{"base_uri":"https://localhost:8080/","height":591},"outputId":"6b8ba6e8-c6a4-49d4-f373-5b7477e5d8f3"},"execution_count":23,"outputs":[{"output_type":"stream","name":"stdout","text":["Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n","Running on public URL: https://2000bfb62937434b61.gradio.live\n","\n","This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"]},{"output_type":"display_data","data":{"text/plain":["<IPython.core.display.HTML object>"],"text/html":["<div><iframe src=\"https://2000bfb62937434b61.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"]},"metadata":{}},{"output_type":"execute_result","data":{"text/plain":[]},"metadata":{},"execution_count":23}]},{"cell_type":"code","source":[],"metadata":{"id":"fbyxs-lbSCnm"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":[],"metadata":{"id":"EmQUFWPfN8P0"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":[],"metadata":{"id":"wWAhEDh9OUgR"},"execution_count":null,"outputs":[]}]}
|
|
|
|