Categories
Misc

Keras Shap.DeepExplainer error object of type ‘NoneType’ has no len()

ratings = tfds.load(‘movielens/100k-ratings’, split=”train”)
movies = tfds.load(‘movielens/100k-movies’, split=”train”)
# Select the basic features.
ratings = ratings.map(lambda x: {
“movie_title”: x[“movie_title”],
“user_id”: x[“user_id”],
“user_rating”: x[“user_rating”],
})
movies = movies.map(lambda x: x[“movie_title”])

# Randomly shuffle data and split between train and test.
tf.random.set_seed(42)
shuffled = ratings.shuffle(100_000, seed=42, reshuffle_each_iteration=False)
train = shuffled.take(80_000)
test = shuffled.skip(80_000).take(20_000)
movie_titles = movies.batch(1_000)
user_ids = ratings.batch(1_000_000).map(lambda x: x[“user_id”])
unique_movie_titles = np.unique(np.concatenate(list(movie_titles)))
unique_user_ids = np.unique(np.concatenate(list(user_ids)))

class MovielensModel(tfrs.models.Model):
def __init__(self, rating_weight: float, retrieval_weight: float) -> None:
# We take the loss weights in the constructor: this allows us to instantiate
# several model objects with different loss weights.
super().__init__()
embedding_dimension = 32
# User and movie models.
self.movie_model: tf.keras.layers.Layer = tf.keras.Sequential([
tf.keras.layers.StringLookup(
vocabulary=unique_movie_titles, mask_token=None),
tf.keras.layers.Embedding(len(unique_movie_titles) + 1, embedding_dimension)
])
self.user_model: tf.keras.layers.Layer = tf.keras.Sequential([
tf.keras.layers.StringLookup(
vocabulary=unique_user_ids, mask_token=None),
tf.keras.layers.Embedding(len(unique_user_ids) + 1, embedding_dimension)
])
# A small model to take in user and movie embeddings and predict ratings.
# We can make this as complicated as we want as long as we output a scalar
# as our prediction.
self.rating_model = tf.keras.Sequential([
tf.keras.layers.Dense(256, activation=”relu”),
tf.keras.layers.Dense(128, activation=”relu”),
tf.keras.layers.Dense(1),
])
# The tasks.
self.rating_task: tf.keras.layers.Layer = tfrs.tasks.Ranking(
loss=tf.keras.losses.MeanSquaredError(),
metrics=[tf.keras.metrics.RootMeanSquaredError()],
)
self.retrieval_task: tf.keras.layers.Layer = tfrs.tasks.Retrieval(
metrics=tfrs.metrics.FactorizedTopK(
candidates=movies.batch(128).map(self.movie_model)
)
)

# The loss weights.
self.rating_weight = rating_weight
self.retrieval_weight = retrieval_weight
def call(self, features: Dict[Text, tf.Tensor]) -> tf.Tensor:
# We pick out the user features and pass them into the user model.
user_embeddings = self.user_model(features[“user_id”])
# And pick out the movie features and pass them into the movie model.
movie_embeddings = self.movie_model(features[“movie_title”])

return (
user_embeddings,
movie_embeddings,
# We apply the multi-layered rating model to a concatentation of
# user and movie embeddings.
self.rating_model(
tf.concat([user_embeddings, movie_embeddings], axis=1)
),
)
def compute_loss(self, features: Dict[Text, tf.Tensor], training=False) -> tf.Tensor:
ratings = features.pop(“user_rating”)
user_embeddings, movie_embeddings, rating_predictions = self(features)
# We compute the loss for each task.
rating_loss = self.rating_task(
labels=ratings,
predictions=rating_predictions,
)
retrieval_loss = self.retrieval_task(user_embeddings, movie_embeddings)
# And combine them using the loss weights.
return (self.rating_weight * rating_loss
+ self.retrieval_weight * retrieval_loss)

model = MovielensModel(rating_weight=1.0, retrieval_weight=0.0)
model.compile(optimizer=tf.keras.optimizers.Adagrad(0.1))

cached_train = train.shuffle(100_000).batch(8192).cache()
cached_test = test.batch(4096).cache()
train_np=np.stack(list(train))

model.fit(cached_train, epochs=3)
metrics = model.evaluate(cached_test, return_dict=True)

model = MovielensModel(rating_weight=0.0, retrieval_weight=1.0)
model.compile(optimizer=tf.keras.optimizers.Adagrad(0.1))

model.fit(cached_train, epochs=3)
metrics = model.evaluate(cached_test, return_dict=True)

train_np=np.stack(list(train))

trained_movie_embeddings, trained_user_embeddings, predicted_rating = model({
“user_id”: np.array([“42”]),
“movie_title”: np.array([“Dances with Wolves (1990)”])
})
print(“Predicted rating:”)
print(predicted_rating)

model = MovielensModel(rating_weight=1.0, retrieval_weight=0.0)
model.compile(optimizer=tf.keras.optimizers.Adagrad(0.1))

import shap
background=train_np[np.random.choice(train_np.shape[0],100,replace=False)]
explainer=shap.DeepExplainer(model,background)
#explainer=shap.DeepExplainer((model.layers[0].input,model.layers[-1].output),background)

Your TensorFlow version is newer than 2.4.0 and so graph support has been removed in eager mode and some static graphs may not be supported. See PR #1483 for discussion. ————————————————————————— TypeError Traceback (most recent call last) <ipython-input-17-3ea83d94ac4d> in <module>() 7 import shap 8 background=train_np[np.random.choice(train_np.shape[0],100,replace=False)] —-> 9 explainer=shap.DeepExplainer(model,background) 10 #explainer=shap.DeepExplainer((model.layers[0].input,model.layers[-1].output),background) 2 frames/usr/local/lib/python3.7/dist-packages/shap/explainers/tf_utils.py in _get_model_output(model) 83 isinstance(model, tf.keras.Model): 84 if len(model.layers[-1]._inbound_nodes) == 0: —> 85 if len(model.outputs) > 1: 86 warnings.warn(“Only one model output supported.”) 87 return model.outputs[0] TypeError: object of type ‘NoneType’ has no len()

explainer=shap.DeepExplainer((model.layers[0].input,model.layers[-1].output),background)

tf.Tensor([[3.402324]], shape=(1, 1), dtype=float32) ————————————————————————— AttributeError Traceback (most recent call last) <ipython-input-18-4d6acf026691> in <module>() 8 background=train_np[np.random.choice(train_np.shape[0],100,replace=False)] 9 #explainer=shap.DeepExplainer(model,background) —> 10 explainer=shap.DeepExplainer((model.layers[0].input,model.layers[-1].output),background) /usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in output(self) 2167 “”” 2168 if not self._inbound_nodes: -> 2169 raise AttributeError(‘Layer ‘ + self.name + ‘ has no inbound nodes.’) 2170 return self._get_node_attribute_at_index(0, ‘output_tensors’, ‘output’) 2171 AttributeError: Layer retrieval_2 has no inbound nodes.

I have tried 2 options but they did not work

submitted by /u/TimelyAbbreviations1
[visit reddit] [comments]

Categories
Misc

Upcoming Event: VPI and Pytorch Interoperability Demo

Join this webinar on June 14 and learn how to program computer vision algorithms using VPI’s Python interface.

Categories
Misc

Solving the World’s Biggest Challenges, Together

Gamers know NVIDIA powers great gaming experiences. Researchers know NVIDIA speeds world-changing breakthroughs. Businesses know us for the AI engines transforming their industries. And NVIDIA employees know the company as one of the best places to work on the planet. More people than ever have a piece of NVIDIA. Roboticists, visual artists, data scientists — Read article >

The post Solving the World’s Biggest Challenges, Together appeared first on NVIDIA Blog.

Categories
Misc

Automate Network Monitoring and Reduce Downtime with the Latest Release of NVIDIA NetQ

Monitor DPUs, validate RoCE deployments, gain network insights through flow-based telemetry analysis, and centrally view network events with NetQ 4.2.0.

NVIDIA NetQ is a highly scalable, modern networking operations tool providing actionable visibility for the NVIDIA Spectrum Ethernet platform. It combines advanced telemetry with a user interface, making it easier to troubleshoot and automate network workflows while reducing maintenance and downtime. 

 We have recently released NetQ 4.2.0, which includes: 

  • Simplified events management
  • Enhanced flow telemetry analysis
  • New RoCE validation
  • New DPU monitoring

For more information about new features and enhancements, see the NetQ 4.2.0 User’s Guide

Simplified events management  

With NetQ 4.2, we have simplified the way network events are communicated through the interface. Events vary in terms of severity—some events are network alarms that may require further investigation, while others are informational notices that may not require intervention. Before this release, NetQ displayed alarms and information events as two separate cards. The NetQ 4.2 release merges the two cards into a single card that, when expanded, displays a dashboard to help you quickly visualize all network events. 

A screenshot of a timeline and device view of error and informational events with NetQ
Figure 1. NetQ events dashboard

The dashboard presents a timeline of events alongside the switches that are causing the most events. You can filter events by type, including interface, network services, system, and threshold-crossing events. 

Acknowledging events helps you focus on active events that need your attention. From the dashboard, you can also create rules to suppress events. This feature is also designed to help you focus on active events, so that known issues or false alarms are not displayed in the same way that errors are displayed. 

Enhanced flow telemetry analysis 

NetQ 4.1.0 introduced fabric-wide network latency and buffer occupancy analysis for Cumulus Linux 5.x data center fabrics. Now, NetQ 4.2 supports partial-path flow telemetry analysis in mixed fabrics—those that use Cumulus Linux 5.x switches in combination with other switches (including non-Cumulus Linux 5.x and third-party switches). Cumulus Linux 5.x devices in the path display flow statistics, such as latency and buffer occupancy. Unsupported devices are represented in the flow analysis as a black bar with a red X, and the device does not display flow statistics. 

A screenshot of the NetQ flow telemetry analysis results view with unsupported device in the path.
Figure 2. NetQ flow telemetry analysis results

In addition, NetQ 4.2 flow telemetry analysis shows contextual ‘What Just Happened’ (WJH) events and drops for the flow under analysis. Switches with WJH events are represented in the flow analysis graph as a red, striped bar. Hovering over the device with the red bar presents a WJH events summary. 

A screenshot of the NetQ flow telemetry analysis showing devices with What Just Happened (WJH) drops and events
Figure 3. NetQ flow telemetry analysis with WJH data

New RoCE validation 

With RDMA over Converged Ethernet (RoCE), you can write to compute or storage elements using remote direct memory access (RDMA) over an Ethernet network instead of using host CPUs. NetQ 4.0.0 introduced RoCE configuration and counters, including the ability to set up various RoCE threshold-crossing alerts (TCAs).

With NetQ 4.2.0, RoCE validation checks: 

  • Lossy- or lossless-mode configuration consistency across switches
  • Consistency of DSCP, service pool, port group, and traffic class settings
  • Consistency of ECN threshold settings
  • Consistency of PFC configuration for lossless mode
  • Consistency of Enhanced Transmission Selection settings

  You can schedule RoCE validation to run periodically or on-demand.   

New DPU monitoring 

NVIDIA BlueField data processing units (DPUs) provide a secure and accelerated infrastructure for any workload by offloading, accelerating, and isolating a broad range of advanced networking, storage, and security services.

NetQ helps you monitor your DPU inventory across the network. You can monitor a DPU OS, ASIC, CPU model, disk, and memory information to help manage upgrades, compliance, and other planning tasks. With NetQ, you can view and monitor key DPU attributes, including installed packages and CPU, disk, and memory utilization.   

A screenshot of the NetQ graphical user interface DPU card showing CPU, memory, and disk utilization.
Figure 4. NetQ-DPU utilization details

In this post, you have seen an overview of some of the new capabilities available with NetQ 4.2.0. For more information, see the NetQ 4.2.0 User’s Guide and explore NetQ with NVIDIA Air.

Categories
Misc

tensorflow lite reduce types of detections

I only need the tensorflow lite example model to detect cars and people, but it detects Many more types of objects. Is there any way to make it detect just these two

submitted by /u/MatsudaYagami
[visit reddit] [comments]