Retriving IGES entity 126 properties from a TopoDS_Edge object of type GeomAbs_BSplineCurve - opencascade

An IGES entity 126 has a property or flag 3 value of 0 = rational or 1 = polynomial. After converting the entity to TopoDS_Edge, how do you retrieve the flag value? Or, if possible how do you check whether a bspline curve gives us a straight line or otherwise?

This worked for me I found the IsRational() function. I hope this is the proper use:
TopoDS_Edge edge = TopoDS::Edge(shape);
BRepAdaptor_Curve curve = BRepAdaptor_Curve(edge);
bool isrational = curve.IsRational();
Better solutions are still welcome. :)

Related

TF 2 - Keras - Merging two seperately trained models to a new ensemble model

Newbie here ;)
I need your help ;)
I have following problem:
I want to merge two TF 2.0 - Keras Models into a new Model.
Expect for example a ResNet50V2 without the head, and retrained on new data - saved weights are provided and loaded:
resnet50v2 = ResNet50V2(weights='imagenet', include_top=False)
#model.summary()
last_layer = resnet50v2.output
x = GlobalAveragePooling2D()(last_layer)
x = Dense(768, activation='relu', name='img_dense_768')(x)
out = Dense(NUM_CLASS, activation='softmax', name='img_output_layer')(x)
resnet50v2 = Model(inputs=resnet50v2.input, outputs=out)
resnet50v2.load_weights(pathToImageModel)
Expect for example a Bert Network retrained on new data - saved weights are provided, in the same way as shown before.
Now I want to skip the last softmax layer from the two models and "merge" them into a new Model.
So I took the layer before the last layer, which names I know:
model_image_output = model_image.get_layer('img_dense_768').output
model_bert_output = model_bert.get_layer('bert_output_layer_768').output
I built two new models with these informations:
model_img = Model(model_image.inputs, model_image_output)
model_bert = Model(model_bert.inputs, model_bert_output)
So now I want to concatenate the outputs of the two models into a new one and add a new "head"
concatenate = Concatenate()([model_img.output,model_bert.output])
x = Dense(512, activation = 'relu')(concatenate)
x = Dropout(0.4)(x)
output = Dense(NUM_CLASS, activation='softmax', name='final_multimodal_output')(x)
model_concat = Model([model_image.input, model_bert.input])
So far so good, model code seemed to be valid but then my knowledge ends.
The main questions are:
Also if the last softmax layers are skipped, the loaded weights should be still available or ?
The new concatened model wants to be build, ok but this ends in this error message, which I only partially understand:
NotImplementedError: When subclassing the Model class, you should implement a call method.
Is there another way to create for example the whole ensemble network and load only the pretrained parts of it and leave the rest beeing trainable?
Am I missing something? I never did subclassing the model class? If so, it was not intended XD
May I ask kindly for some hints ?
Thanks in advance!!
Kind regards ragitagha
UPDATE:
So to find my mistake more quickly and provide the solution in a more precise way:
I had to change the lines
concatenate = Concatenate()([model_img.output,model_bert.output])
x = Dense(512, activation = 'relu')(concatenate)
x = Dropout(0.4)(x)
output = Dense(NUM_CLASS, activation='softmax', name='final_multimodal_output')(x)
model_concat = Model([model_image.input, model_bert.input])
to:
concatenate = Concatenate()([model_img.output,model_bert.output])
x = Dense(512, activation = 'relu')(concatenate)
x = Dropout(0.4)(x)
output = Dense(NUM_CLASS, activation='softmax', name='final_multimodal_output')(x)
model_concat = Model([model_image.input, model_bert.input], output)

Why do I have problem when I train my model in pytorch?

I'm new with PyTorch and AI but I have some trouble when I try to train my model.
I just create my Dataset and my Dataloader
train_dataset = TensorDataset(tensor_train,tensor_label)
train_dataloader = DataLoader(train_dataset,batch_size=32,shuffle=True)
And after this my criterion and optimiser
criterion = nn.CrossEntropyLoss()
optimiser=optim.Adam(net.parameters(),lr=0.2)
And I try to train it with
for epoch in range(10):
for data in train_dataloader:
inputs,labels = data
output = net(torch.Tensor(inputs))
loss = criterion(output,labels.to(device))
optimiser.zero_grad()
loss.backward()
optimiser.step()
But I got this error
d:\py\lib\site-packages\torch\nn\modules\module.py in <lambda>(t)
321 Module: self
322 """
--> 323 return self._apply(lambda t: t.type(dst_type))
324
325 def float(self):
TypeError: dtype must be a type, str, or dtype object
I will be happy if someone finds the problem, thanks.
I see two possible problems:
1) Your dataloader outputs a tensor, so you don't need to create another tensor. Just do this:
output = net(inputs)
2) Are you sending your model to device? If yes, you need to send the inputs as well. If not, you don't need to do this with the outputs:
loss = criterion(output,labels)
However, I'm not sure if the error you're getting is not related to these 2 points. Consider posting the line in your code (instead of the lib). Also, consider including more information about tensor_train and tensor_label
Ty for reply but the problem was coming from another thing
I was creating my model like this
class Perceptron(nn.Module):
def __init__(self):
super(Perceptron,self).__init__()
self.type = nn.Linear(4,3)
def forward(self,x):
return self.type(x)
net = Perceptron().to(device)
and the nn.Module was already getting a type attribute thats why i was getting this error( i thing) , then i solve by change self.type by self.anythingElseThanType

Making a multi-plot from an sf object using and displaying one unique color key

Is it possible to make a multi-plot from an sf object, using and displaying one unique color key for all the subplots?
The default of an sf object is a multi-plot of all the attributes, if that is what you mean, as described in sf vignette 5. Is this achieving what you are looking for?
r
library(sf)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
plot(nc[,1:4], pal = sf.colors(10))

Logical-Indexing for Matlab-object-arrays

Is there any way in Matlab R2011b to apply logical-indexing to object-arrays? The objects which fulfill specific condition(s) regarding their properties should be returned. At best the solution is also possible with object-arrays that are a property of another object (aggregation).
In my project there are a lot of entities which have to be identified by their manifold features. Matlab objects with their properties provide a clear data foundation for this purpose. The alternative of using structs (or cells) and arrays of indices seems to be too confusing. Unfortunately the access to the properties of objects is a little bit complicated.
For Example, all Objects in myArray with Element.val==3 should be returned:
elementsValIsThree = myElements(Element.val==3);
Best solution so far:
find([myElements.val]==3);
But this doesn't return the objects and not the absolute index if a subset of myElements is input.
Another attempt returns only the first Element and needs constant properties:
myElements(Element.val==3);
A minimal example with class definition etc. for clarification:
% element.m
classdef Element
properties
val
end
methods
function obj = Element(value)
if nargin > 0 % to allow empty construction
obj.val = value;
end
end
end
end
Create array of Element-Objects:
myElements(4) = Element(3)
Now myElements(4) has val=3.
I'm not sure I understood the question, but the logical index can be generated as
arrayfun(#(e) isequal(e.val,3), myElements);
So, to pick the elements of myElements whose val field equals 3:
elementsValIsThree = myElements(arrayfun(#(e) isequal(e.val,3), myElements));

setting object properties value for object array in matlab

I have created an array of objects and I would like assign a property value in a vector operation without using a for loop. Unfortunately I get an error.
A simplified example of the problem.
classdef clsMyClass < handle
properties
dblMyProperty1
end
methods
function obj = clsMyClass()
end
end
end
And when running
vecMyArray = clsMyClass.empty(100,0);
vecMyArray(100) = clsMyClass;
vecMyArray.dblMyProperty1 = 1:100;
We get the following error:
??? Incorrect number of right hand side elements in dot name
assignment. Missing [] around left hand side is a likely cause.
Any help would be appreciated.
I see what you're trying to do now. Use disperse from the MATLAB File Exchange:
>> [vecMyArray.dblMyProperty1] = disperse(1:100);
>> vecMyArray(1).dblMyProperty1
ans =
1
>> vecMyArray(10).dblMyProperty1
ans =
10
You can use the deal function for exactly this purpose:
[vecMyArray.dblMyProperty1] = deal(1:100);
See: http://www.mathworks.com/company/newsletters/articles/whats-the-big-deal.html
Edit: No you can't, actually; that'll set them to all be the vector 1:100.
I think you'll find your answer here in "Struct array errors." Even though this is a class, similar rules apply.
Unfortunately missing [] is not the cause, since adding them causes more errors. The cause is that you cannot assign the same value to all fields of the same name at once, you must do it one at a time, as in the following code:
So you'll need:
for ii=1:100
vecMyArray(ii).dblMyProperty1 = ii;
end
I know it's not satisfying, but I think it at least helps us to definitively understand this error.

Resources