Пример #1
0
    wide_preprocessor = WidePreprocessor(wide_cols=wide_cols,
                                         crossed_cols=crossed_cols)
    X_wide = wide_preprocessor.fit_transform(df)

    tab_preprocessor = TabPreprocessor(
        embed_cols=cat_embed_cols,  # type: ignore[arg-type]
        continuous_cols=continuous_cols,
        already_standard=already_standard,
    )
    X_tab = tab_preprocessor.fit_transform(df)

    text_processor = TextPreprocessor(word_vectors_path=word_vectors_path,
                                      text_col=text_col)
    X_text = text_processor.fit_transform(df)

    image_processor = ImagePreprocessor(img_col=img_col, img_path=img_path)
    X_images = image_processor.fit_transform(df)

    wide = Wide(wide_dim=np.unique(X_wide).shape[0], pred_dim=1)
    deepdense = TabMlp(
        mlp_hidden_dims=[64, 32],
        mlp_dropout=[0.2, 0.2],
        column_idx=tab_preprocessor.column_idx,
        embed_input=tab_preprocessor.embeddings_input,
        continuous_cols=continuous_cols,
    )
    # # To use TabResnet as the deepdense component simply:
    # deepdense = TabResnet(
    #     blocks_dims=[64, 32],
    #     dropout=0.2,
    #     column_idx=tab_preprocessor.column_idx,
import numpy as np
import pandas as pd
import pytest

from pytorch_widedeep.preprocessing import ImagePreprocessor

df = pd.DataFrame({'galaxies': ['galaxy1.png', 'galaxy2.png']})
img_col = 'galaxies'
imd_dir = 'images'
processor = ImagePreprocessor()
X_imgs = processor.fit_transform(df, img_col, img_path=imd_dir)

###############################################################################
# There is not much to test here, since I only resize.
###############################################################################
def test_sizes():
	img_width = X_imgs.shape[1]
	img_height = X_imgs.shape[2]
	assert np.all((img_width==processor.width, img_height==processor.height))
import numpy as np
import pandas as pd
import os

from pytorch_widedeep.preprocessing import ImagePreprocessor

full_path = os.path.realpath(__file__)
path = os.path.split(full_path)[0]
df = pd.DataFrame({"galaxies": ["galaxy1.png", "galaxy2.png"]})
img_col = "galaxies"
imd_dir = os.path.join(path, "images")
processor = ImagePreprocessor(img_col=img_col, img_path=imd_dir)
X_imgs = processor.fit_transform(df)


###############################################################################
# There is not much to test here, since I only resize.
###############################################################################
def test_sizes():
    img_width = X_imgs.shape[1]
    img_height = X_imgs.shape[2]
    assert np.all(
        (img_width == processor.width, img_height == processor.height))
def test_notfittederror():
    processor = ImagePreprocessor(img_col=img_col, img_path=imd_dir)
    with pytest.raises(NotFittedError):
        processor.transform(df)