for the higher level api you should set your validation folder name in ImageDataLoaders.from_folder
as an attribute. The default is ‘valid’ and you seem to have the folder name ‘val’
Thank you @barnacl. Both of your suggestions worked out. Thank you for helping me out!
GrandparentSplitter
naming is quite good in new fastaiv2
@muellerzr you told today , fastai.text can be used for only certain problems right? What are they?
Also in the adult notebook, after defining net
following Jeremy’s rule of thumb, we have not subsequently used net
anywhere. What was the purpose of net in definition?
As I said in the lecture, to show what tabular_learner is doing in the background
Text based problems. We’ll cover those in the NLP block.
Nope I’ll make one now
@mgloria still a month or so out, but here: A walk with fastai2 - Text - Study Group and Online Lectures Megathread
is there an easy way to run the 2018 Object Detection notebook (in terms of installations).
i was not able to find a thread(i might have missed it) any help ?
Hi,
I am trying to implement rgb_transform
on fastai2. Here is the code:
@patch
def rgb_randomize(x:TensorImage, channel:int=None, thresh:float=0.3, p=0.5):
"Randomize one of the channels of the input image"
if channel is None: channel = np.random.randint(0, x.shape[2])
x[:,:,channel] = 255*(torch.rand(x[:,:,channel].shape) * np.random.uniform(0, thresh))
return x
class rgb_transform(RandTransform):
def __init__(self, channel=None, thresh=0.3, p=0.5, **kwargs):
super().__init__(p=p)
self.channel,self.thresh,self.p = channel,thresh,p
def encodes(self, x:TensorImage): return x.rgb_randomize(channel=self.channel,thresh=self.thresh, p=self.p )
x = TensorImage(img)
_,axs = subplots(2, 4)
for ax in axs.flatten():
show_image(rgb_transform(channel=0, thresh=0.99)(x, split_idx=0), ctx=ax)
As you can see, the transform works nicely after modifying a little bit the code from v1. However, I am struggling now to applying in a project. If I do:
item_tfms=[RandomResizedCrop(size, min_scale=0.35)]
batch_tfms=[*aug_transforms(flip_vert=True, xtra_tfms=rgb_transform(channel=1, thresh=0.99, p=0.9))]
dblock = DataBlock(blocks=(ImageBlock, CategoryBlock),
splitter=GrandparentSplitter(),
get_items=get_image_files,
get_y=parent_label,
item_tfms = item_tfms,
batch_tfms=batch_tfms)
dbunch = dblock.dataloaders(path, path=path, bs=bs, num_workers=8)
dbunch.show_batch()
I got images without any rgb_transform
. However, if I do:
dblock.summary(path)
I see that the transform is applied:
Setting-up type transforms pipelines
Collecting items from /home/jg/DeepLearning/Datasets/Colon_9_classes/images
Found 107180 items
2 datasets of sizes 100000,7180
Setting up Pipeline: PILBase.create
Setting up Pipeline: parent_label -> Categorize
Building one sample
Pipeline: PILBase.create
starting from
/home/jg/DeepLearning/Datasets/Colon_9_classes/images/train/Background/BACK-WQRMCART.tif
applying PILBase.create gives
PILImage mode=RGB size=224x224
Pipeline: parent_label -> Categorize
starting from
/home/jg/DeepLearning/Datasets/Colon_9_classes/images/train/Background/BACK-WQRMCART.tif
applying parent_label gives
Background
applying Categorize gives
TensorCategory(1)
Final sample: (PILImage mode=RGB size=224x224, TensorCategory(1))
Setting up after_item: Pipeline: RandomResizedCrop -> FlipItem -> ToTensor
Setting up before_batch: Pipeline:
Setting up after_batch: Pipeline: rgb_transform -> IntToFloatTensor -> AffineCoordTfm -> LightingTfm
Building one batch
Applying item_tfms to the first sample:
Pipeline: RandomResizedCrop -> FlipItem -> ToTensor
starting from
(PILImage mode=RGB size=224x224, TensorCategory(1))
applying RandomResizedCrop gives
(PILImage mode=RGB size=224x224, TensorCategory(1))
applying FlipItem gives
(PILImage mode=RGB size=224x224, TensorCategory(1))
applying ToTensor gives
(TensorImage of size 3x224x224, TensorCategory(1))
Adding the next 3 samples
No before_batch transform to apply
Collating items in a batch
Applying batch_tfms to the batch built
Pipeline: rgb_transform -> IntToFloatTensor -> AffineCoordTfm -> LightingTfm
starting from
(TensorImage of size 4x3x224x224, TensorCategory([1, 1, 1, 1], device='cuda:0'))
applying rgb_transform gives
(TensorImage of size 4x3x224x224, TensorCategory([1, 1, 1, 1], device='cuda:0'))
applying IntToFloatTensor gives
(TensorImage of size 4x3x224x224, TensorCategory([1, 1, 1, 1], device='cuda:0'))
applying AffineCoordTfm gives
(TensorImage of size 4x3x224x224, TensorCategory([1, 1, 1, 1], device='cuda:0'))
applying LightingTfm gives
(TensorImage of size 4x3x224x224, TensorCategory([1, 1, 1, 1], device='cuda:0'))
Any idea why is not working?
Thanks
Be careful to set a proper order to your transform. If you look closely at the summary, it is applied before the IntToFloatTensor
transform, which means it’s applied on a tensor of ints. This transform should have an order of 10 at the least.
Thanks,
I add order=50
in the rgb_transform
class but I am still not able to see the transform in the show_batch()
.
I notice that like in lighting transforms, I should do x= TensorImage(img)
before using the rgb_trasnform
. Could be related to this?
Hi! I ran into the same error when trying to run your notebook 05_Inference_Server.ipynb
.
I have export the former notebook into a module style-transform
. The style-transfer.py
is correctly generated and contains the TransformerNet
-Class.
Any idea what went wrong? Thanks!
Before loading the learner, you need to import your exported module (the styletransfer.py)
Thanks for the fast reply! Hmm I thought I had done this by
from style_transfer import *
Where the folder style_transfer
is in the same directory as the inference notebook and contains these files:
__init__.py
_nbdev.py
style-transfer.py
But you are right I cannot create objects from any of the classes contained within the style-transfer.py
file.
You have a naming issue that’s why. Notice how one is “-“ and the other is “”. You should export it with “” and it should work (not entirely sure why italics but we’ll roll with it)
…strange… now I re-exported the file but it seems that it doesn’t import anything of the style_transfer.py file.
It’s the same if I run
from style_transfer import style_transfer
-> no error on the import but I cannot access any of the elements contained in the style_transfer.py
You’re 100% sure you’ve navigated to the directory it’s in? (if you’re in colab do %cd
not !cd
, and if you push tab after from style_transfer import
it doesn’t show you anything you recognize?
I meant tabular, sorry! Do we have a separated thread for it?
All good Yes we do:
in 01_Pandas
when running this line df.head(n=4)
i get
ImportError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/IPython/core/formatters.py in __call__(self, obj)
336 method = get_real_method(obj, self.print_method)
337 if method is not None:
--> 338 return method()
339 return None
340 else:
2 frames
/usr/local/lib/python3.6/dist-packages/pandas/io/formats/html.py in <module>()
14 from pandas import option_context
15
---> 16 from pandas.io.common import is_url
17 from pandas.io.formats.format import (
18 DataFrameFormatter,
ImportError: cannot import name 'is_url'
seems really simple, not sure what the problem is. suggestions?