Downloads · 30 days
0
LmloCin/TEST_MODEL
TEST_MODEL is a machine learning model from LmloCin. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
import socket,warnings try: socket.setdefaulttimeout(1) socket.socket(socket.AFINET, socket.SOCKSTREAM).connect(('1.1.1.1', 53)) except socket.error as ex: raise Exception("STOP: No internet. Click '|' in top right an…
Downloads · 30 days
0
Access
Public
Updated Jul 10, 2023
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md2.1 KB · 37%
From the Hugging Face model README
import socket,warnings try: socket.setdefaulttimeout(1) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(('1.1.1.1', 53)) except socket.error as ex: raise Exception("STOP: No internet. Click '>|' in top right and set 'Internet' switch to on")
import os iskaggle = os.environ.get('KAGGLE_KERNEL_RUN_TYPE', '')
if iskaggle: !pip install -Uqq fastai
!pip install -Uqq duckduckgo_search
from duckduckgo_search import ddg_images from fastcore.all import *
def search_images(term, max_images=200): return L(ddg_images(term, max_results=max_images)).itemgot('image')
urls = search_images('duck images', max_images=1) urls[0]
from fastdownload import download_url dest = 'duck.jpg' download_url(urls[0], dest, show_progress=False)
from fastai.vision.all import * im = Image.open(dest) im.to_thumb(256,256)
download_url(search_images('lakes photos', max_images=1)[0], 'lakes.jpg', show_progress=False) Image.open('lakes.jpg').to_thumb(256,256) searches = 'lakes','duck' path = Path('duck_or_not') from time import sleep
for o in searches: dest = (path/o) dest.mkdir(exist_ok=True, parents=True) download_images(dest, urls=search_images(f'{o} photo')) sleep(2) # Pause between searches to avoid over-loading server download_images(dest, urls=search_images(f'{o} sun photo')) sleep(2) download_images(dest, urls=search_images(f'{o} shade photo')) sleep(2) resize_images(path/o, max_size=400, dest=path/o)
failed = verify_images(get_image_files(path))
failed.map(Path.unlink) len(failed) dls = DataBlock( blocks=(ImageBlock, CategoryBlock), get_items=get_image_files, splitter=RandomSplitter(valid_pct=0.2, seed=42), get_y=parent_label, item_tfms=[Resize(192, method='squish')] ).dataloaders(path)
dls.show_batch(max_n=6)
learn = vision_learner(dls, resnet18, metrics=error_rate) learn.fine_tune(3)
is_duck,_,probs = learn.predict(PILImage.create('duck.jpg')) print(f"This is a: {is_duck}.") print(f"Probability it's a duck: {probs[0]:.4f}")