Laurits commited on
Commit
f9458a9
·
1 Parent(s): 39f6d6c

Renamed model.pth to model.pkl

Browse files
Files changed (3) hide show
  1. app.py +1 -1
  2. model.pth → model.pkl +0 -0
  3. test.ipynb +66 -0
app.py CHANGED
@@ -1,7 +1,7 @@
1
  from fastai.vision.all import *
2
  import gradio as gr
3
 
4
- learn = load_learner('model.pth')
5
 
6
  def classify_image(img):
7
  celebrity_name,_,probs = learn.predict(img)
 
1
  from fastai.vision.all import *
2
  import gradio as gr
3
 
4
+ learn = load_learner('model.pkl')
5
 
6
  def classify_image(img):
7
  celebrity_name,_,probs = learn.predict(img)
model.pth → model.pkl RENAMED
File without changes
test.ipynb CHANGED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from fastai.vision.all import *"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 2,
15
+ "metadata": {},
16
+ "outputs": [
17
+ {
18
+ "ename": "UnpicklingError",
19
+ "evalue": "invalid load key, 'v'.",
20
+ "output_type": "error",
21
+ "traceback": [
22
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
23
+ "\u001b[0;31mUnpicklingError\u001b[0m Traceback (most recent call last)",
24
+ "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m learner \u001b[39m=\u001b[39m load_learner(\u001b[39m'\u001b[39;49m\u001b[39mmodel.pth\u001b[39;49m\u001b[39m'\u001b[39;49m)\n",
25
+ "File \u001b[0;32m~/ENTER/envs/fastai-env/lib/python3.11/site-packages/fastai/learner.py:446\u001b[0m, in \u001b[0;36mload_learner\u001b[0;34m(fname, cpu, pickle_module)\u001b[0m\n\u001b[1;32m 444\u001b[0m distrib_barrier()\n\u001b[1;32m 445\u001b[0m map_loc \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mcpu\u001b[39m\u001b[39m'\u001b[39m \u001b[39mif\u001b[39;00m cpu \u001b[39melse\u001b[39;00m default_device()\n\u001b[0;32m--> 446\u001b[0m \u001b[39mtry\u001b[39;00m: res \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39;49mload(fname, map_location\u001b[39m=\u001b[39;49mmap_loc, pickle_module\u001b[39m=\u001b[39;49mpickle_module)\n\u001b[1;32m 447\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mAttributeError\u001b[39;00m \u001b[39mas\u001b[39;00m e: \n\u001b[1;32m 448\u001b[0m e\u001b[39m.\u001b[39margs \u001b[39m=\u001b[39m [\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mCustom classes or functions exported with your `Learner` not available in namespace.\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mRe-declare/import before loading:\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\t\u001b[39;00m\u001b[39m{\u001b[39;00me\u001b[39m.\u001b[39margs[\u001b[39m0\u001b[39m]\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m]\n",
26
+ "File \u001b[0;32m~/ENTER/envs/fastai-env/lib/python3.11/site-packages/torch/serialization.py:815\u001b[0m, in \u001b[0;36mload\u001b[0;34m(f, map_location, pickle_module, weights_only, **pickle_load_args)\u001b[0m\n\u001b[1;32m 813\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mRuntimeError\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 814\u001b[0m \u001b[39mraise\u001b[39;00m pickle\u001b[39m.\u001b[39mUnpicklingError(UNSAFE_MESSAGE \u001b[39m+\u001b[39m \u001b[39mstr\u001b[39m(e)) \u001b[39mfrom\u001b[39;00m \u001b[39mNone\u001b[39;00m\n\u001b[0;32m--> 815\u001b[0m \u001b[39mreturn\u001b[39;00m _legacy_load(opened_file, map_location, pickle_module, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mpickle_load_args)\n",
27
+ "File \u001b[0;32m~/ENTER/envs/fastai-env/lib/python3.11/site-packages/torch/serialization.py:1033\u001b[0m, in \u001b[0;36m_legacy_load\u001b[0;34m(f, map_location, pickle_module, **pickle_load_args)\u001b[0m\n\u001b[1;32m 1027\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mhasattr\u001b[39m(f, \u001b[39m'\u001b[39m\u001b[39mreadinto\u001b[39m\u001b[39m'\u001b[39m) \u001b[39mand\u001b[39;00m (\u001b[39m3\u001b[39m, \u001b[39m8\u001b[39m, \u001b[39m0\u001b[39m) \u001b[39m<\u001b[39m\u001b[39m=\u001b[39m sys\u001b[39m.\u001b[39mversion_info \u001b[39m<\u001b[39m (\u001b[39m3\u001b[39m, \u001b[39m8\u001b[39m, \u001b[39m2\u001b[39m):\n\u001b[1;32m 1028\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mRuntimeError\u001b[39;00m(\n\u001b[1;32m 1029\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mtorch.load does not work with file-like objects that do not implement readinto on Python 3.8.0 and 3.8.1. \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 1030\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mReceived object of type \u001b[39m\u001b[39m\\\"\u001b[39;00m\u001b[39m{\u001b[39;00m\u001b[39mtype\u001b[39m(f)\u001b[39m}\u001b[39;00m\u001b[39m\\\"\u001b[39;00m\u001b[39m. Please update to Python 3.8.2 or newer to restore this \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 1031\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mfunctionality.\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m-> 1033\u001b[0m magic_number \u001b[39m=\u001b[39m pickle_module\u001b[39m.\u001b[39;49mload(f, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mpickle_load_args)\n\u001b[1;32m 1034\u001b[0m \u001b[39mif\u001b[39;00m magic_number \u001b[39m!=\u001b[39m MAGIC_NUMBER:\n\u001b[1;32m 1035\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mRuntimeError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mInvalid magic number; corrupt file?\u001b[39m\u001b[39m\"\u001b[39m)\n",
28
+ "\u001b[0;31mUnpicklingError\u001b[0m: invalid load key, 'v'."
29
+ ]
30
+ }
31
+ ],
32
+ "source": [
33
+ "learner = load_learner('model.pkl')"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": null,
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": []
42
+ }
43
+ ],
44
+ "metadata": {
45
+ "kernelspec": {
46
+ "display_name": "fastai-env",
47
+ "language": "python",
48
+ "name": "python3"
49
+ },
50
+ "language_info": {
51
+ "codemirror_mode": {
52
+ "name": "ipython",
53
+ "version": 3
54
+ },
55
+ "file_extension": ".py",
56
+ "mimetype": "text/x-python",
57
+ "name": "python",
58
+ "nbconvert_exporter": "python",
59
+ "pygments_lexer": "ipython3",
60
+ "version": "3.11.5"
61
+ },
62
+ "orig_nbformat": 4
63
+ },
64
+ "nbformat": 4,
65
+ "nbformat_minor": 2
66
+ }