I build a model on fastai v2.3.1. When I try to call functions show_batch and show_results it does not show anything. Here is the problematic code:
from fastai.vision.all import *
from fastai.data.all import *
import fastai.vision
import zipfile as zf
import random
import timeit
fields = DataBlock(blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
get_y=yer,
splitter=RandomSplitter(valid_pct=0.2, seed=random.randint(0, 10)),
item_tfms=RandomResizedCrop(224, min_scale=0.5),
batch_tfms=aug_transforms()
)
dls = fields.dataloaders(os.path.join(Path(os.getcwd()), "train"), num_workers=0, bs=32)
dls.show_batch()
learn = cnn_learner(dls, resnet18, metrics=error_rate)
learn.fine_tune(2)
learn.show_results()
I can use model but these functions.
I ran into the same thing, found the answer here:
https://www.debuggingtissue.com/latest-articles/how-to-save-fastai-plots-when-using-an-external-server-or-terminal-environment
Basically PyPlot is creating a graphics object but not displaying it, so you need to immediately tell plt to save/show the buffer.
So it's as easy as typing "plt.show()" after the show_results() call!
import matplotlib.pyplot as plt
...
learn.show_results()
plt.show()
(Took me forever to find that out, hope this helps!)
Related
We can list out spreadsheet present in google drive using below command
from google.colab import drive
drive.mount('/content/drive')
!ls -l /content/drive/'Shared drives'
but unable to read spreadsheet using below command
import gspread
from oauth2client.client import GoogleCredentials
gc = gspread.authorize(GoogleCredentials.get_application_default())
gc.open('/content/drive/'Shared drives/data.gsheet').data available
and also one more problem we have space in sheetname(data available) and we don't have access to change sheetname
I have refer link:: https://colab.research.google.com/notebooks/io.ipynb
Kindly help on it.
You can use gc.open_by_url('gsheets_url') to open the document (no need to mount the drive). For the sheet name, you can use gsheets.worksheet('sheet name').
So on your case it'd go something like:
from google.colab import auth
auth.authenticate_user()
import gspread
from oauth2client.client import GoogleCredentials
# setup
gc = gspread.authorize(GoogleCredentials.get_application_default())
# read data and put it in a dataframe
gsheets = gc.open_by_url('your-link')
sheets = gsheets.worksheet('data available').get_all_values()
df = pd.DataFrame(sheets[1:], columns=sheets[0])
(credits to this post)
Update to the answer by Murilo Cunha, as it gives errors for authentication
from google.colab import auth
auth.authenticate_user()
import gspread
from google.auth import default
creds, _ = default()
gc = gspread.authorize(creds)
import pandas as pd
# read data and put it in a dataframe
gsheets = gc.open_by_url('Your link')
sheets = gsheets.worksheet('data available').get_all_values()
df = pd.DataFrame(sheets[1:], columns=sheets[0])
It's helpful if you could say what is the exact error you get when you run this script. However, I notice there are redundant quotes in following script,
gc.open('/content/drive/'Shared drives/data.gsheet')
replace extra above by following,
gc.open('/content/drive/Shared drives/data.gsheet')
Another option is to try gc.open_by_url() instead of gc.open()
I imported math.
import 'dart:math';
But how can I call "PI" constant?
This is not working.
math.pi / 12.0
you should
import 'dart:math' as math; instead of just import 'dart:math';
because when you use the as keyword you provide the imported library a name so you can reference it anywhere in your file
As an alternative to the accepted answer, you can keep importing without a prefix, and reference pi as just pi:
import "dart:math" show pi;
main() {
print(pi / 12);
}
This works just as well as prefixing. It's a matter of taste which one you prefer.
First import 'dart:math';
then use pi/12.0 instead of math.PI/12.0 it should work fine.
Below are my imports used in my java program. What I am trying to do is, to create a client of type MqttCient and then use the method connectWithResuls as follows
client.connectWithResult(opts);
the problem is eclipse underscores the lie mentioned above with red squiggle, and I do not know why, I also referred to Paho java docs here.
please let me know why the aforementioned method is not recognised.
Imports
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.IMqttToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
i have some Python Code working properly its some kinda simple thing using opencv.
for example
import cv2
x = cv2.imread('Dog6.jpg')
cv2.imwrite('new2.jpg')
setup.py is
from distutils.core import setup
import py2exe
import cv2
setup(console=['name.py'])
but i am unable to create exe of this code with py2exe.
is there another method to create exe of such program ?
Error is
ImportError:numpy.core.multiarray failed to import
Put the line:
import numpy
Into your script, i.e the first file and try again.
I need to import the fallowing,But in blackberry there is no predefined imports as i need.
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javacard.framework.SystemException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.kobjects.base64.Base64;
all these shows error.
When i add jar6 library it does n't show any error but i got packing failed.
I need to import these files.
can any one please post how can i import these files.
Thank u in advance.
BlackBerry uses J2ME which is Java 1.3. You won't be able to use Java 6 classes. Instead you should look at the BlackBerry API. It has classes for encryption but you'll need to rewrite your code to use them.