Developer chat

I’ve also tried the everything from conda-forge method and found it to work well (didn’t check their docs though, I just set channel when creating the env and then in config). Though I haven’t run into many issues with mixed conda-forge/default apart from the one that prompted that attempt (think it was an mkl or some numpy dependency thing around pycuda or similar). So I wasn’t specifically testing known problems.
Tha’s ignoring the issue of repeated switches of low level packages (conda/certs etc) when you mix them which is annoying but doesn’t seem to cause issues. This can also be mostly resolved by using -c defaults -c conda-forge to explicitly favour the defaults when the version is the same. Or there’s a --no-channel-priority option that also avoids the constant switching, using version ahead of channel priority/ Note this is different to the strict channel priority setting conda docs say to use, that favours channel over version, the --no-channel-priority means when version is the same on conda-forge ad default it won’t switch to whatever you’re installing from, this being due to the fact that any channels specified on the CLI override all your channel settings, hence -c defaults -c conda-forge means default is still higher priority.

1 Like

I’ve updated spacy in the fastai anaconda channel to the latest version, along with its dependencies. Installs fine and tests passing. This will hopefully fix problems with incompatibilities in spacy with latest Anaconda.

Should Flatten be replaced by PyTorch’s nn.Flatten?

The current Flatten implementation uses the Shape operation which is not supported in earlier versions of ONNX, for example, you cannot use an exported fastai model in ONNX.js. Using the built-in nn.Flatten() in PyTorch fixes this issue and thus improves compatibility. For backwards compatibility reasons, we might just want to keep the custom Flatten class and simply inherit from nn.Flatten.

I would have submitted a PR, but I am not sure what notebooks I should change that refer to Flatten.

1 Like

Our flatten has the option to completely flatten the input so there might need some extra care for this.

Does the ONNX exporter handle a custom subclass (even if it doesn’t override forward)? Maybe:

def Flatten(full:bool=False):
    "Flatten `x` to a single dimension, often used at the end of a model. `full` for rank-1 tensor"
    return nn.Flatten(start_dim=0 if full else 1)

Assuming nothing is fussy about it not being a class anymore.

1 Like

I just tested this and it works. I replace Flatten in the create_head function with your definition and exported to ONNX, then imported the model in onnx.js and it works the same as if I used nn.Flatten directly (as expected).

In Learner.pred_batch with reconstruct=True it does return [ds.reconstruct(o) for o in res] but this tries to apply the reconstruct of the item not the label. Presumably it should be ds.y.reconstruct. I guess it should also call ds.y.analyze_preds first for where preparation is needed there, in line with Learner.get_preds.

One issue I ran into while preparing a PR was that when making a test I couldn’t get reconstruct to work on the fake_learner. The network has five outputs from a linear and the loss is F.nll_loss. But then all it does to the output is a torch.exp (based on _loss_func2activ(). So it’s still five items and it can’t reconstruct a RandomLabel. Looks like there should probably be an argmax somewhere along the way but not quite sure where. Should that be in RandomLabel.analyze_preds (currently no-op)? Or am I missing something?

From a search nothing in fastai seems to use reconstruct=True here, so no issues there.

I am having some issues / confusion with excluding validation sets. I have been using fastai 1.0.59 making a custom databunch object that creates a bunch via:

cls.create(train_list, valid_list, path=path, num_workers=num_workers, bs=1, device=device, **dl_kwargs)

where the user can specify valid_list = None. This works fine but the output seems ugly:

epoch     train_loss  valid_loss  train_reward  valid_reward  time    
0         0.002569    #na#        -0.372000     0             00:03     
1         0.007665    #na#        -0.396000     0             00:03     
2         0.002273    #na#        0.612000      0             00:03 

I noticed in the Recorder:

class Recorder(LearnerCallback):
    "A `LearnerCallback` that records epoch, loss, opt and metric data during training."
    _order=-10
    def __init__(self, learn:Learner, add_time:bool=True, silent:bool=False):
        super().__init__(learn)
        self.opt = self.learn.opt
        self.train_dl = self.learn.data.train_dl
        self.no_val,self.silent,self.add_time = False,silent,add_time

That no_val seems to always be false. Am I missing something about how / where to set it to true? Is there an example in fastai code that sets this field to true?

I would expect something like self.no_val = not self.learn.data.empty_val instead.

I am dealing with the same problem. Even i thought of using Interpretation.preds but the losses contains more values than the datapoints itself. Somehow modifying the top_loss method may help, I guess. If you made a custom MultiLabelClassificationInterpretation , let me know, i am expecting it might help me too.

I didn’t end up doing much work on multi-label prediction so not entirely sure of the most useful approach. Here’s a notebook with some code and some output from my data, which isn’t included. It could do with more testing so may fail on your data. Also not the best data for testing, oddly shaped 1600x256px images so layout may be better done for more standard images and not at all obvious from images what the output should be. But should hopefully give you some idea.
The problem with the current code (from memory so could be a bit off on details) is that the losses from Learner.get_preds are flattened, unreduced losses so a list of len(ds)*data.c. It looks like the current code is trying to deal with the sort of output as well as non-flattened output but it ends up mixing up losses/truths from the two so you get the wrong losses/items displayed.
I implemented two approaches, one that reduces the losses to a per-item loss and one that shows per-prediction losses. I suspect that the best approach depends a bit on the dataset in terms of the number of classes and how often they co-occur.

I have just discovered that VS Code support Jupyter Notebook. The experience is quite similar (same shortcuts). Does anyone have an idea should we migrate to use notebook with an IDE (VS Code or Pycharm) or it is better stay with the browser based notebook. Thanks :smiley:

1 Like

How do we install fastai in kaggle now ? I’ve tried !pip install git+https://github.com/fastai/fastai_dev
But get the errors below.

Thanks

If you are talking about v2, it’s in github.com/fastai/fastai2 now (and on pipy too so you can pip install fastai2).

1 Like

How do I get predictions on a test data set?

Hello all,

I have images and they are organized in the following directory structure:

path
train
class1
class2
valid
class1
class2
test
class1
class2\

I am able to train with validation. However, how do I get predictions on my test data set? The labels are based on the directory structure within test (class1 and class2). I’m using the latest fastai package for python3 (fastai==1.0.60). When I look through the forum, I keep getting outdated answers (usually referring to version 0.7 ???).

Any help would be appreciated and thank you in advance.

Rodney

I think I know the answer now. I’m going to create a new data using ImageDataBunch and point valid to my test directory. I’ll update my success/failure here after implementation.

Thank you!

Rodney

Hi, I am getting this weird error whenever my model is trying to download the pre-trained model through some learner like cnn_learner or unet_learner. I’m wasting so much time searching for a solution. Help me if you any way to get out of this.

Have a look here: https://stackoverflow.com/questions/23964048/python-unpickling-stack-underflow . It seems that the model files are broken, maybe the download failed in the middle. Maybe clearing the fastai cache will help?

I’ve tried clearing the torch cache where the model gets downloaded but no difference. I even tried to download some other pretrained model like resnet50, it downloads till 99% and then shows this error.

Are you using multiple GPUs by any chance, or using multiple processes to download and save the model file into the same file name?

No, I’m not doing that. In a virtual environment created for fastai I’m running this in a notebook thats it.

edit: solved that was due to proxy server :slight_smile: