def forward(self, x): # create max pool layers - every batch can have different thus max_pool layer should be dynamic mp1 = MaxPool1d(x.shape[2] - self._max_pool1_fix, 1) mp2 = MaxPool1d(x.shape[2] - self._max_pool2_fix, 1) mp3 = MaxPool1d(x.shape[2] - self._max_pool3_fix, 1) x = self._embeddings(x).unsqueeze( dim=2 ) # out_dim = [batch, max_len_words, 1, max_len_char, embed_dim] # 3 Filters # each filter is have different window size: each word is represented as concatenation of # the max pool of the 3 filters [ max_pool(filter1), max_pool(filter2), max_pool(filter3) ] x1 = torch.stack([ mp1(self._filter1(x[idx, :]).squeeze(dim=3)).squeeze(dim=1) for idx in range(x.shape[0]) ]) x2 = torch.stack([ mp2(self._filter2(x[idx, :]).squeeze(dim=3)).squeeze(dim=1) for idx in range(x.shape[0]) ]) x3 = torch.stack([ mp3(self._filter3(x[idx, :]).squeeze(dim=3)).squeeze(dim=1) for idx in range(x.shape[0]) ]) x = torch.cat([x1, x2, x3], dim=2) # out_dim = [ batch_size, return x
def __init__(self, d, es_idx, ent_vec_dim, rel_vec_dim, cfg, max_length, Evocab=40990, Rvocab=13): super(LSTMTuckER, self).__init__() self.Eembed = nn.Embedding(Evocab, cfg.hSize, padding_idx=0) self.Rembed = nn.Embedding(Rvocab, cfg.hSize, padding_idx=0) self.tucker = TuckER(d, ent_vec_dim, rel_vec_dim, cfg) self.es_idx = es_idx self.elstm = LSTM(cfg.hSize, int(ent_vec_dim / 2), num_layers=2, batch_first=True, dropout=0.2, bidirectional=True) self.epooling = MaxPool1d(kernel_size=max_length) #batch_first: If ``True``, then the input and output tensors are provided as (batch, seq, feature). Default: ``False`` self.rlstm = LSTM(cfg.hSize, int(rel_vec_dim / 2), num_layers=2, batch_first=True, dropout=0.2, bidirectional=True) self.rpooling = MaxPool1d(kernel_size=1) self.loss = torch.nn.BCELoss()
def __init__(self, in_size): super().__init__() #self.conv1 = Conv1d(in_size[1], 64, kernel_size=100, stride=50) self.conv1 = Conv1d(in_size[1], 64, kernel_size=4, stride=2) self.mp1 = MaxPool1d(kernel_size=2, stride=2) self.conv2 = Conv1d(64, 64, kernel_size=2, stride=1) self.mp2 = MaxPool1d(kernel_size=2, stride=2) self.get_linear_size(torch.rand(in_size)) self.fc1 = Linear(self.linear_in_size, 100) self.fc2 = Linear(100, 1)
def __init__(self, input_length, channels, kernel_size, stride, padding, hidden_layer_nodes, output_layer_nodes): super().__init__() ## 1. Convolve the tensor using 2 convolutional layers self.conv_layers = Sequential( # The 1st Layer: Conv1d( channels, # 1 channel for each dimension of word embedding 8, kernel_size, stride, padding), ReLU(), MaxPool1d(2), # The 2nd Layer: Conv1d(8, 16, kernel_size, stride, padding), ReLU(), MaxPool1d(2), # The 3rd Layer: Conv1d(16, 64, kernel_size, stride, padding), ReLU(), MaxPool1d(2)) self.dropout = Dropout() ## 2. Define fully connected input dimension def n_extracted_features(conv_layers, input_length, last_out_channel): '''Helper function for creating the attribute "self.N_EXTRACTED_FEATURES" that computes the numbers of nodes to feed into the flat, fully connected layer. ''' N_LAYERS = len(conv_layers) / 3 # validate input if input_length % 2**N_LAYERS != 0: raise Exception( 'input_length should evenly divide 2**N_LAYERS.') POOLED_DIM = input_length / 2**N_LAYERS return int(last_out_channel * POOLED_DIM) # = the volume of the flattened tensor # being fed forward to the FC layer ## 3. Specify fully connected network using the above dimension calculations. self.N_EXTRACTED_FEATURES = n_extracted_features( self.conv_layers, input_length, 64 # must = last Conv1d's out channels ) self.fc_layers = Sequential( Linear(self.N_EXTRACTED_FEATURES, hidden_layer_nodes), Linear(hidden_layer_nodes, output_layer_nodes) ) # output_layer_nodes equals the number of classes in the target
def __init__(self, d, es_idx, ent_vec_dim, rel_vec_dim, cfg, max_length, Evocab=40990, Rvocab=13): super(CNNTuckER, self).__init__() self.Eembed = nn.Embedding(Evocab, cfg.hSize, padding_idx=0) self.Rembed = nn.Embedding(Rvocab, cfg.hSize, padding_idx=0) self.es_idx = es_idx self.Evocab = Evocab self.ecnn = Sequential(Conv1d(in_channels=cfg.hSize, out_channels=ent_vec_dim, kernel_size=cfg.window_size), MaxPool1d(kernel_size=max_length-cfg.window_size+1)) self.rcnn = Sequential(Conv1d(in_channels=cfg.hSize, out_channels=rel_vec_dim, kernel_size=1), MaxPool1d(kernel_size=1)) self.tucker = TuckER(d, ent_vec_dim, rel_vec_dim, cfg) self.loss = torch.nn.BCELoss()
def __init__(self): super(Net, self).__init__() self.cnn_layers = Sequential( # convolutional layer Conv1d(in_channels=9, out_channels=1, kernel_size=50, stride=5, padding=1), BatchNorm1d(num_features=1), ReLU(inplace=True), MaxPool1d(kernel_size=10, stride=3), Dropout(.5), # convolutional layer Conv1d(in_channels=1, out_channels=8, kernel_size=50, stride=5, padding=1), BatchNorm1d(num_features=8), ReLU(inplace=True), MaxPool1d(kernel_size=100, stride=10), Dropout(.5), # convolutional layer Conv1d(in_channels=8, out_channels=4, kernel_size=50, stride=1, padding=0), BatchNorm1d(num_features=4), ReLU(inplace=True), MaxPool1d(kernel_size=10, stride=3), Dropout(.5), # final convolutional layer to compress to 2 channels (the number of possible classes). Conv1d(in_channels=4, out_channels=2, kernel_size=10, stride=1, padding=0), #BatchNorm1d(num_features = 2), # linear to map to our 1 output. # sigmoid will create output between 0 and 1 Linear(in_features=13, out_features=1), Sigmoid(), )
def __init__(self, in_channels=2, num_layers=5, filter_width=11, channels=[16, 32, 64, 128, 256], dropout=0.3, rate=44100, duration=0.5, flat_dim=512): assert num_layers == len(channels) super(ConvTwin, self).__init__() extra_px = filter_width // 2 channels = [in_channels] + channels total_len = int(2**np.floor(np.log2(rate * duration))) conv_block = lambda in_ch, out_ch, p=dropout, fw=filter_width, pd=extra_px: nn.Sequential( Conv1d(in_ch, out_ch, kernel_size=fw, padding=pd), BatchNorm1d(out_ch), ReLU(), Dropout(p=p), MaxPool1d(kernel_size=2) ) convs = [] for i in range(1, len(channels)): convs.append(conv_block(channels[i - 1], channels[i])) self.dense = Linear(total_len * channels[-1] // (2**len(convs)), flat_dim) self.L = total_len self.convs = convs self.convs = nn.Sequential(*self.convs)
def __init__(self, batch_size, inputs, outputs): super(CnnRegressor, self).__init__() self.batch_size = batch_size self.inputs = inputs self.outputs = outputs self.input_bn = nn.BatchNorm1d(8) #batch normalization self.input_layer = Conv1d(inputs, batch_size, 1) #input layer self.max_pooling_layer = MaxPool1d(1) #max-pooling layer self.conv_layer1 = Conv1d(batch_size, 128, 1) #first conv layer self.conv_bn1 = nn.BatchNorm1d(128) #batch normaliation after first conv self.conv_layer2 = Conv1d(128, 256, 1) #second conv layer self.conv_bn2 = nn.BatchNorm1d(256) #batch normaliation after second conv self.flatten_layer = Flatten() #flatten layer to vectorize the data self.linear_layer = Linear(256, 64) #linear regression self.output_layer = Linear(64, outputs) #output layer
def __init__(self, num_conv1d_banks, num_highway_blocks, in_dims, out_dims, activation): super(CBHG, self).__init__() self.num_highway_blocks = num_highway_blocks self.conv1d_banks = Conv1dBanks(num_conv1d_banks, in_dims, out_dims, activation) # Since kernel_size = 2, padding + 1 self.max_pool1d = MaxPool1d(kernel_size=2, stride=1, padding=1) self.projection1 = Conv1dNorm(in_dims=num_conv1d_banks * out_dims, out_dims=out_dims, kernel_size=3, activation_fn=activation) self.projection2 = Conv1dNorm(in_dims=out_dims, out_dims=out_dims, kernel_size=3, activation_fn=None) self.highway = HighwayNet(in_dims=out_dims) self.gru = GRU(out_dims, out_dims, batch_first=True, bidirectional=True)
def __init__(self, hidden_channels, num_layers, GNN=GCNConv, k=0.6): super(DGCNN, self).__init__() if k < 1: # Transform percentile to number. num_nodes = sorted([data.num_nodes for data in train_dataset]) k = num_nodes[int(math.ceil(k * len(num_nodes))) - 1] k = max(10, k) self.k = int(k) self.convs = ModuleList() self.convs.append(GNN(train_dataset.num_features, hidden_channels)) for i in range(0, num_layers - 1): self.convs.append(GNN(hidden_channels, hidden_channels)) self.convs.append(GNN(hidden_channels, 1)) conv1d_channels = [16, 32] total_latent_dim = hidden_channels * num_layers + 1 conv1d_kws = [total_latent_dim, 5] self.conv1 = Conv1d(1, conv1d_channels[0], conv1d_kws[0], conv1d_kws[0]) self.maxpool1d = MaxPool1d(2, 2) self.conv2 = Conv1d(conv1d_channels[0], conv1d_channels[1], conv1d_kws[1], 1) dense_dim = int((self.k - 2) / 2 + 1) dense_dim = (dense_dim - conv1d_kws[1] + 1) * conv1d_channels[1] self.lin1 = Linear(dense_dim, 128) self.lin2 = Linear(128, 1)
def __init__(self, train_dataset, feature_dim, hidden_dim, num_classes, dropout, k=0.6): super(Sparse_Three_Concat, self).__init__() self.hidden_dim = hidden_dim self.dropout = dropout if k <= 1: # Transform percentile to number. sampled_train = train_dataset[:1000] num_nodes = sorted([g.num_nodes for g in sampled_train]) k = num_nodes[int(math.ceil(k * len(num_nodes))) - 1] k = max(10, k) self.k = int(k) self.ib1 = InceptionBlock(feature_dims, hidden_dim) self.ib2 = InceptionBlock(hidden_dim, hidden_dim) self.ib3 = InceptionBlock(hidden_dim, hidden_dim) self.ln1 = Linear(hidden_dim * 3, hidden_dim) self.ln2 = Linear(hidden_dim * 3, hidden_dim) self.ln3 = Linear(hidden_dim * 3, hidden_dim) self.final = InceptionBlock(hidden_dim, 1) conv1d_channels = [16, 32] total_latent_dim = hidden_dim + 1 conv1d_kws = [total_latent_dim, 5] self.conv1 = Conv1d(1, conv1d_channels[0], conv1d_kws[0], conv1d_kws[0]) self.maxpool1d = MaxPool1d(2, 2) self.conv2 = Conv1d(conv1d_channels[0], conv1d_channels[1], conv1d_kws[1], 1) dense_dim = int((self.k - 2) / 2 + 1) dense_dim = (dense_dim - conv1d_kws[1] + 1) * conv1d_channels[1] self.lin1 = Linear(dense_dim, 128) self.lin2 = Linear(128, num_classes)
def __init__(self, batch_size, inputs, outputs): #Initializing the superclass and storing the parameters super(CnnRegressor, self).__init__() self.batch_size = batch_size self.inputs = inputs self.outputs = outputs #Defining the input layer with the input size, kernel size and output size self.input_layer = Conv1d(inputs, batch_size, 1) #Defining a max pooling layer with a kernel size self.max_pooling_layer = MaxPool1d(1) #Defining another convolutional layer self.conv_layer = Conv1d(batch_size, 128, 1) #Defining a flatten layer self.flatten_layer = Flatten() #defining a linear layer with inputs and output as the arguments self.linear_layer = Linear(128, 64) #Defining the output layer self.output_layer = Linear(64, outputs)
def __init__(self, in_channels, out_channels, slope=0.01, kern_size=5, max_pool=2, eps=1e-05, momentum=0.1, use_pool=True): super(DoubleConvAndPool, self).__init__() padding = (kern_size) // 2 # just a step size of 1 and 'same' padding self.conv1 = Conv1d(in_channels, out_channels, kernel_size=kern_size, padding=padding) self.batch_norm_1 = BatchNorm1d(out_channels) self.relu_1 = LeakyReLU(negative_slope=slope) self.conv2 = Conv1d(out_channels, out_channels, kernel_size=kern_size, padding=padding) self.batch_norm_2 = BatchNorm1d(out_channels) self.relu_2 = LeakyReLU(negative_slope=slope) self.pool = MaxPool1d(kern_size, stride=max_pool, padding=padding) self.use_pool = use_pool
def __init__(self, args, train_dataset, dataset, hidden_channels, num_layers, max_z, GNN=GCNConv, k=0.6, use_feature=False, dataset_name=None, node_embedding=None): super(WLGNN_model, self).__init__() self.use_feature = use_feature self.node_embedding = node_embedding self.args = args if k <= 1: # Transform percentile to number. if args.dynamic_train: sampled_train = train_dataset[:1000] else: sampled_train = train_dataset num_nodes = sorted([g.num_nodes for g in sampled_train]) k = num_nodes[int(math.ceil(k * len(num_nodes))) - 1] k = max(10, k) self.k = int(k) self.max_z = max_z if "social" in dataset_name: self.w_z = 50000 else: self.w_z = max_z self.w_embedding = Embedding(self.w_z, hidden_channels) self.z1_embedding = Embedding(self.max_z, hidden_channels) self.z2_embedding = Embedding(self.max_z, hidden_channels) self.convs = ModuleList() initial_channels = hidden_channels * 3 if self.use_feature: initial_channels += dataset.num_features * 2 if self.node_embedding is not None: initial_channels += node_embedding.embedding_dim self.convs.append(GNN(initial_channels, hidden_channels)) for i in range(0, num_layers - 1): self.convs.append(GNN(hidden_channels, hidden_channels)) self.convs.append(GNN(hidden_channels, 1)) conv1d_channels = [16, 32] total_latent_dim = hidden_channels * num_layers + 1 conv1d_kws = [total_latent_dim, 5] self.conv1 = Conv1d(1, conv1d_channels[0], conv1d_kws[0], conv1d_kws[0]) self.maxpool1d = MaxPool1d(2, 2) self.conv2 = Conv1d(conv1d_channels[0], conv1d_channels[1], conv1d_kws[1], 1) dense_dim = int((self.k - 2) / 2 + 1) dense_dim = (dense_dim - conv1d_kws[1] + 1) * conv1d_channels[1] self.lin1 = Linear(dense_dim, 128) self.lin2 = Linear(128, 1)
def __init__(self, sample_size, conv_bank_max_filter_size=16, conv_projections_channel_size=(128, 128), num_highways=4): super(CBHG, self).__init__() self.sample_size = sample_size self.relu = ReLU() # conv_bank_max_filter_size sets of 1-D convolutional filters self.conv1d_banks = [] for k in range(1, conv_bank_max_filter_size + 1): self.conv1d_banks.append( BatchNormConv1d(in_channels=sample_size, out_channels=sample_size, kernel_size=k, stride=1, padding=k // 2, activation=self.relu)) self.conv1d_banks = ModuleList(modules=self.conv1d_banks) # max pooling of conv bank (to increase local invariances) self.max_pool1d = MaxPool1d(kernel_size=2, stride=1, padding=1) out_features = [conv_bank_max_filter_size * sample_size ] + conv_projections_channel_size[:-1] activations = [self.relu ] * (len(conv_projections_channel_size) - 1) + [None] # conv1d projection layers self.conv1d_projections = [] for (in_size, out_size, ac) in zip(out_features, conv_projections_channel_size, activations): self.conv1d_projections.append( BatchNormConv1d(in_channels=in_size, out_channels=out_size, kernel_size=3, stride=1, padding=1, activation=ac)) self.conv1d_projections = ModuleList(modules=self.conv1d_projections) # Highway layers self.pre_highway = Linear( in_features=conv_projections_channel_size[-1], out_features=sample_size, bias=False) self.highways = ModuleList(modules=[ Highway(in_size=sample_size, out_size=sample_size) for _ in range(num_highways) ]) # bi-directional GPU layer self.gru = GRU(input_size=sample_size, hidden_size=sample_size, num_layers=1, batch_first=True, bidirectional=True)
def __init__(self): super(ConvNet, self).__init__() self.input_layer = Conv1d(3, 10, 1) self.max_pooling_layer = MaxPool1d(1) self.conv_layer = Conv1d(10, 50, 1) self.flatten_layer = Flatten() self.linear_layer = Linear(50, 50) self.output_layer = Linear(50, 1)
def __init__(self,btach_size,inputs, outputs): super(CnnRegressor, self).__init__() self.batch_size = batch_size self.inputs = inputs self.outputs = outputs self.input_layer = Conv1d(inputs, batch_size, 1) self.max_pooling_layer = MaxPool1d(1) self.conv_layer = Conv1d(batch_size, 128, 1) self.max_pooling_layer_1 = MaxPool1d(1) self.conv_layer_1 = Conv1d(128, 128, 1) self.flatten_layer = Flatten() self.linear_layer = Linear(128, 64) self.output_layer = Linear(64, outputs)
def forward(self, x): mp1 = MaxPool1d(x.shape[2] - self.mp1_fix, 1) mp2 = MaxPool1d(x.shape[2] - self.mp2_fix, 1) mp3 = MaxPool1d(x.shape[2] - self.mp3_fix, 1) x = self.E(x).unsqueeze(dim=2) x1 = tc.stack([ mp1(self.f1(x[i, :]).squeeze(dim=3)).squeeze(dim=1) for i in range(x.shape[0]) ]) x2 = tc.stack([ mp2(self.f2(x[i, :]).squeeze(dim=3)).squeeze(dim=1) for i in range(x.shape[0]) ]) x3 = tc.stack([ mp3(self.f3(x[i, :]).squeeze(dim=3)).squeeze(dim=1) for i in range(x.shape[0]) ]) x = tc.cat([x1, x2, x3], dim=2) return x
def __init__(self): super(CNN, self).__init__() self.cnn_layers = Sequential( Conv1d(1, 32, kernel_size=4, stride=2, padding=0), BatchNorm1d(32), ReLU(inplace=True), Conv1d(32, 64, kernel_size=8, stride=2, padding=0), ReLU(inplace=True), MaxPool1d(3, stride=2), )
def __init__(self, num_features): super().__init__() self.num_features = num_features self.conv1_input = Conv1d(1, 1, kernel_size=3, padding=1) self.relu = ReLU() self.conv1 = Conv1d(1, 16, kernel_size=3) self.conv2 = Conv1d(16, 16, kernel_size=3, padding=1) self.pool1 = MaxPool1d(kernel_size=3) self.flatten = Flatten() self.linear1 = Linear(16, 10) self.linear2 = Linear(10, 10) self.linear3 = Linear(10, 1)
def __init__(self, batch_size, inputs, outputs): super(CnnRegressor, self).__init__() self.batch_size = batch_size self.inputs = inputs self.outputs = outputs self.input_layer = Conv1d(inputs, batch_size, 1) self.max_pooling_layer = MaxPool1d(1) self.conv_layer = Conv1d(batch_size, 256, kernel_size=4, stride=2, padding=2) self.flatten_layer = Flatten() self.linear_layer = Linear(256, 64) self.output_layer = Linear(64, outputs)
def __init__(self, in_features: int, out_features: int, N_layers: int = 2, **kwargs): super(MaxOut, self).__init__() self.maxout = Sequential( Linear(in_features, N_layers * out_features, **kwargs), Reshape(1, N_layers * out_features), MaxPool1d(N_layers), Reshape(out_features), )
def __init__(self, batch_size,inputs,outputs): super(CnnRegressor,self).__init__() self.batch_size = batch_size self.inputs = inputs self.outputs = outputs self.input_layer = Conv1d(inputs,batch_size,1) self.batch_normalization = BatchNorm1d(batch_size) self.max_pooling_layer = MaxPool1d(1) self.conv_layer = Conv1d(batch_size,128,1) self.batch_normalization2 = BatchNorm1d(128) self.max_pooling_layer2 = MaxPool1d(1) self.flatten_layer = Flatten() #define a linear layer (ips,opts) self.linear_layer = Linear(128,64) #define the output layer self.output_layer = Linear(64,outputs)
def __init__(self, in_channel,out_channel,cnn_ker,cnn_stride,\ pool_stride,pool_ker ,bn): super(CnnModule, self).__init__() mylist = ModuleList() mylist.append(Conv1d(in_channel,out_channel, kernel_size=cnn_ker, \ stride=cnn_stride, padding=0, bias=False)) if bn == 1: mylist.append(BatchNorm1d(out_channel)) if pool_ker > 0: mylist.append(MaxPool1d(kernel_size=pool_ker, stride=pool_stride)) self.mylist = Sequential(*mylist)
def __init__(self,batch_size,inputs,outputs): super(CnnRegressor,self).__init__() self.batch_size=batch_size self.inputs=inputs self.outputs=outputs self.input_layer=Conv1d(inputs,batch_size,1) self.max_pooling_layer = MaxPool1d(1) self.conv_layer=Conv1d(batch_size,256,1) self.conv_layer2=Conv1d(256,256,1) self.flatten_layer=Flatten() self.non_linear_layer=Sequential(Linear(256,256)) self.output_layer=Sequential(Linear(256,outputs))
def __init__(self, num_classes, device='cpu'): super(CNN1d, self).__init__() self.device = device self.conv_model = Sequential( Conv1d(in_channels=11, out_channels=32, kernel_size=3), ReLU(), Conv1d(in_channels=32, out_channels=64, kernel_size=3), ReLU(), MaxPool1d(2), Dropout(0.25)) self.linear_model = Sequential( Lambda(lambda x: x.view(x.size(0), -1)), Lambda( lambda x: Linear(x.size(1), 128).to(self.device).forward(x)), ReLU(), Dropout(0.5), Linear(128, num_classes), Softmax(dim=1))
def __init__(self): super(Model2, self).__init__() self.conv1 = Conv1d(in_channels=ModelBase.InputShape[1], out_channels=ModelBase.InputShape[1], kernel_size=Model2.ConvolutionKernelSize, padding=Model2.ConvolutionPadding) self.maxpool1 = MaxPool1d(Model2.PoolingKernelSize) self.fcInputShape = (ModelBase.InputShape[0] // Model2.PoolingKernelSize, Model2.InputShape[1]) self.fc1 = Linear(self.fcInputShape[0] * self.fcInputShape[1], self.fcInputShape[0] * self.fcInputShape[1]) torch.nn.init.xavier_uniform_(self.conv1.weight) torch.nn.init.xavier_uniform_(self.fc1.weight)
def __init__(self, batch_size, inputs, outputs): # Initialize the superclass and store the parameters super(CnnRegressor, self).__init__() self.batch_size = batch_size self.inputs = inputs self.outputs = outputs # Define the input layer # (input channels, output channels, kernel size) self.input_layer = Conv1d(inputs, batch_size,1) # Batch normalization self.input= torch.nn.BatchNorm1d(inputs) # Define a max pooling layer self.max_pooling_layer = MaxPool1d(1) # Define another convolution layer self.conv_layer = Conv1d(batch_size, 128,1) # Define a max pooling layer self.max_pooling_layer2 = MaxPool1d(1) self.flatten_layer = Flatten() # Define a linear layer # (inputs, outputs) self.linear_layer = Linear(128, 64) # Finally, define the output layer self.output_layer = Linear(64, outputs)
def __init__(self): super(ConvBackend, self).__init__() bn_size = 256 self.conv1 = Conv1d(bn_size, 2 * bn_size, 2, 2) self.norm1 = BatchNorm1d(bn_size * 2) self.pool1 = MaxPool1d(2, 2) self.conv2 = Conv1d(2 * bn_size, 4 * bn_size, 2, 2) self.norm2 = BatchNorm1d(bn_size * 4) self.linear = Linear(4 * bn_size, bn_size) self.norm3 = BatchNorm1d(bn_size) self.linear2 = Linear(bn_size, 500) self.loss = CrossEntropyLoss() self.validator = _validate
def __init__(self, batch_size, inputs, outputs): super(CnnRegressor, self).__init__() self.batch_size = batch_size self.inputs = inputs self.outputs =outputs # Define the input layer # (input channels, output channels, kernel size) self.input_layer = Conv1d(inputs, batch_size, 1) self.max_pooling_layer = MaxPool1d(1) # Constructor value: Kernel size = 1 self.conv_layer = Conv1d(batch_size, 128, 1) self.conv_layer2 = Conv1d(128, 64, 1) self.flatten_layer = Flatten() self.liner_layer = Linear(64, 32) self.output_layer = Linear(32, outputs)